源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

node.js入门实例helloworld详解

  • 时间:2021-06-11 16:27 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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 [img]http://files.jb51.net/file_images/article/201512/20151223125411707.jpg?20151123125438[/img] 提示服务启动(Server has started),然后在浏览器中输入http://localhost:2222/,即可以看到下图的效果。 [img]http://files.jb51.net/file_images/article/201512/20151223125442167.jpg?20151123125511[/img] 执行成功后的效果 希望本文所述对大家node.js程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部