Nodejs v4.x.0API文档学习(1)简介

文档参考地址:https://nodejs.org/dist/latest-v4.x/docs/api/

简介

下面是用nodejs编写的一个web服务的例子,返回"Hello World"。

const http = require('http');

http.createServer( (request, response) => {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World\n');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

来运行这个服务,先把上面的代码保存在一个命名为example.js的文件中,然后使用node程序执行

$ node example.js
Server running at http://127.0.0.1:8124/

文档中所有的例子都能同样的方式去执行。

  


 

posted @ 2016-03-14 17:44  光尘9022  阅读(239)  评论(0编辑  收藏  举报