zoukankan      html  css  js  c++  java
  • Learn Node.js

    Learn Node.js

    Node:

    1. 脱离浏览器运行的JS,运行在服务端
    2. 基于Chrome浏览器的V8引擎,使用V8虚拟机解析和执行JS代码

    创建简单的服务器:

    1. 创建一个server.js的文件
      $ touch server.js
    2. 使用require函数加载模块http
    3. 调用http.createServer()函数创建服务器
    4. 调用listen方法指定监听端口
    5. 在命令行中打开当前页面,执行node server.js
       $ node server.js
    6. 页面中打开127.0.0.1:端口,打开你创建的页面
      http.createServer(function(req,rep){
          rep.writeHead(200,{'Content-Type':'text/plain'});
          rep.write('Hello World');
          response.end();
      }).listen();
      

         

    服务器处理请求:

    • request--------------请求对象(包含:请求查询字符串,参数,内容,HTTP头部等属性)
    • request.url----------请求地址
    • request.method----请求动作
    • response------------响应对象
    • response.write()----响应内容
    • response.end()-----结束响应
  • 相关阅读:
    nginx防止盗链
    Nginx防盗链详细设置
    [bzoj2127]happiness
    [bzoj2400]Optimal Marks
    [bzoj1738]发抖的牛
    [bzoj1741]穿越小行星群
    [bzoj3123]森林
    [bzoj2588]Count on a tree
    [bzoj3144]切糕
    [bzoj1787]紧急集合
  • 原文地址:https://www.cnblogs.com/zhuxiaopeng/p/7047709.html
Copyright © 2011-2022 走看看