node.js开发hello world

在你的 D 盘下面创建一个 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 ');

}).listen(8888); // 端口号

// 终端打印信息

console.log('Server running at http://127.0.0.1:8888/');
--------------------------------------------
点击保存

然后在 D 盘打开 CMD,输入 node server.js

最后打开浏览器,访问 http://127.0.0.1:8888/。

成功效果如下图:

 

原文地址:https://www.cnblogs.com/MarsJiang/p/node_helloWord.html