使用Node.js快速创建web服务

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gfd54gd5f46/article/details/78647027


步骤一、引入 required 模块


var http = 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/');


步骤三、浏览器请求服务器


打开浏览器访问 http://127.0.0.1:8888/


1


猜你喜欢

转载自blog.csdn.net/gfd54gd5f46/article/details/78647027
今日推荐