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

2.node.js 入门

2016-07-07 12:48 495 查看
1.Hello World
打一个一个文本编辑器,在其中输入
console.log('Hello World');
并保存为helloworld.js。打开dos窗口进入该文件的目录运行
node helloworld.js 执行则可以看到输出的helloworld
2.Node.js命令行工具
node -v 版本
node -e eval scipt eval(“console.log('呵呵')”);
例:node -e "console.log('hello world')"; 直接执行
node 直接进入编译模式
console.log("111")
第一行是输出、第二行是返回值
3.建立HTTP服务器
创建一个app.js

var http=require('http')
http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/html'});
res.write('<h1>Node.js</h1>');
res.end('<p>PCAT</p>');
}).listen(3000);
console.log('HTTP server is listening at port 3000.');
接下来node app.js 打开浏览器访问 http://localhost:3000即可。这样就部署了一个web。比如tomcat、resin更加方便 4.调试代码:
npm install -supervisor -g
安装supervisor 来控制调试代码。 不需要每次停止重启node.js的服务
使用supervisor app.js启动
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: