nodejs-2-第一个应用

    xiaoxiao2022-07-13  141

    第一个应用

    1、引入required模块
    使用require指令载入http模块,实例化http: var http = require("http")
    2、创建服务器
    使用http.createServer()的方法创建服务器,并使用listen方法绑定8080端口。通过request、response参数来接收和响应数据。实例: var http = require('http'); http.createServer(function (request, response) { // 创建http头,返回状态值&内容类型 response.writeHead(200, {'Content-Type': 'text/plain'}); // 发送响应数据 response.end('Hello World!'); }).listen(8080); // 监听8080端口
    最新回复(0)