代潇瑞博客

node.js入门范例helloworld

| 点击次数:6471

将下面的代码保存为:server.js存到E盘下面的node目录中。


var http = require('http');

function myNode(request, response){

response.writeHead(200, {'Content-type':'text/plain'});

response.write('hello world'); //hello world

response.end();

}

http.createServer(myNode).listen(2222); //监听2222端口

console.log('Server has started'); //在控制台提示服务启动


然后在windows命令行输入node e:/node/server.js


node.jshelloworld1


提示服务启动(Server has started),然后在浏览器中输入http://localhost:2222/,即可以看到下图的效果。


node.jshelloworld2

执行成功后的效果

【相关推荐】

触屏版 | 电脑版

Copyright © 2013 代潇瑞博客手机版

QQ: 446673330

粤ICP备13071969号-1