我是靠谱客的博主 笨笨老虎,这篇文章主要介绍node.js入门实例helloworld详解,现在分享给大家,希望可以做个参考。

本文实例讲述了node.js入门实例helloworld。分享给大家供大家参考,具体如下:

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

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

执行成功后的效果

希望本文所述对大家node.js程序设计有所帮助。

最后

以上就是笨笨老虎最近收集整理的关于node.js入门实例helloworld详解的全部内容,更多相关node内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(142)

评论列表共有 0 条评论

立即
投稿
返回
顶部