首页 > 编程语言 >04.node创建第一个应用

04.node创建第一个应用

时间:2023-02-11 13:45:23浏览次数:35  
标签:node HTTP 04 创建 Hello text http response

// 使用 require 指令来载入 http 模块
var http = require('http');

http.createServer(function (request, response) {

    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // 发送响应数据 "Hello World"
    response.end('Hello World\n');
}).listen(8888);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');

运行:

 

 

演示:

 

标签:node,HTTP,04,创建,Hello,text,http,response
From: https://www.cnblogs.com/mxx520/p/17111305.html

相关文章