• node.js基本使用


    1.引入http模块(node的核心模块)
      const http = require("http");
    2.createServer来创建服务器
      http.createServer((req,res)=>{ //req:request、res:response
        res.writeHead(200,{"content-type":"text/plain"}); //200为状态码,其中的对象为响应头
        res.end("你好"); //回复响应信息,做结尾,必须要写
      }).listen(9000); //指定端口为9000
      console.log("http://localhost:9000"); //作为提示信息显示在终端中
      之后在终端中输入node 文件名,会显示提示信息,然后在浏览器中输入网址localhost:设置的端口号,即可显示内容
    3.request的方法
      request.url:请求的地址
      request.method:请求的方式(默认为GET)
      request.headers:请求头
      request.body:接收post传递的参数
      request.query:接收get传递的参数
      request.request:接收任意方式传递过来的数据
    4.response的方法
      response.write():回复响应信息,可以写多个
      response.end():回复响应信息,做结尾,必须要写,只能写一个
      response.statusCode:设置状态码,如response.statusCode = 200;
      response.setHeader():设置响应头,如response.setHeader("content-type","text/plain");
      response.writeHead():statusCode与setHeader的综合写法

  • 相关阅读:
    POJ 3468_A Simple Problem with Integers(树状数组)
    POJ 3468_A Simple Problem with Integers(线段树)
    ZOJ 2770_Burn the Linked Camp
    ZOJ 2770_Burn the Linked Camp
    POJ 3169_Layout
    POJ 3169_Layout
    POJ 3684_Physics Experiment
    POJ 3255_Roadblocks
    POJ 3723 Conscription【最小生成树】
    POJ 3279 Fliptile【枚举】
  • 原文地址:https://www.cnblogs.com/Leslie-Cheung1584304774/p/10544073.html
Copyright © 2020-2023  润新知