现在的位置: 首页 -> 前端学习 -> JS前端 -> node.js入门范例helloworld

node.js入门范例helloworld

2015-06-15 00:29评论数 0 ⁄ 被浏览 6416 views+

将下面的代码保存为: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

执行成功后的效果

 

文章出自:https://www.daixiaorui.com/read/159.html 本站所有文章,除注明出处外皆为原创,转载请注明本文地址,版权所有。

目前有 0 条评论  @我要评论

    您的每一个评论都是对我的一份支持

     博客二维码

    昵称 *

    邮箱 *