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

创建第一个node应用 hello node

2017-03-15 00:00 127 查看
//使用require指令载入http模块
var http = require("http");

//使用http.createServer()方法创建服务器,使用listen方法绑定8888端口,
//参数request,response接受和响应数据
http.createServer(function(request,response){
//发送请求头
response.writeHead(200,{'Content-Type':'text/plain'});

//发送响应数据 hello world
response.end('hello node!');

}).listen(8888);

//终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  node