您的位置:首页 > Web前端 > Node.js

【Node】 Js 创建一个简单服务器

2018-01-12 22:10 591 查看
创建一个server.js文件,写下内容:

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 ' target='_blank'>http://127.0.0.1:8888/');[/code] 在命令窗口执行如下:
node server.js
Server running at http://127.0.0.1:8888/[/code] 


然后在浏览器打开窗口:http://127.0.0.1:8888

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: