nodejs02---demo

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')";   直接执行        
3. node :直接进入编译模式
    然后输入:    console.log("111")
        第一行是输出、第二行是返回值
4.建立HTTP服务器
    创建一个app.js         
var http=require('http')   //引入http包拿到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.调试代码:
下载最新版node,进入node安装目录C:\Program Files (x86)\nodejs\node_modules\npm,执行npm install -supervisor -g
 安装supervisor包来控制调试代码。 (未完成)
 
 进入编译模式:node
 执行:supervisor app.js
代码改动刷新页面就修改了, 不需要每次停止重启node.js的服务

 

app.js

var http=require('http')//引入http包拿到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.');

helloworld.js

console.log("Hello word爱爱爱");

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值