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启动
打一个一个文本编辑器,在其中输入
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启动
相关文章推荐
- Reverse Nodes in k-Group
- 1.Node.js是什么?
- 《leetCode》: Count Complete Tree Nodes
- nodejs加密Crypto的实例代码
- Node.js DES加密的简单实现
- 推荐几个学习Node.js的站点
- Node.js 学习笔记
- Node.js des加密
- Restify一
- eclipse 安装node js 调试环境
- hadoop源码解析---INodeReference机制 推荐
- Node.js入门之快速搭建开发环境
- Node.js DES加密的简单实现
- nodejs加密Crypto的实例代码
- windows 下 express 应用于生产环境
- 为基于Express的应用上手,准备 Git与VS Code
- [LintCode] Swap Nodes in Pairs 成对交换节点
- Node.js NPM国内镜像
- Nodejs实现代理服务器配置
- 深入解析桶排序算法及Node.js上JavaScript的代码实现