zoukankan      html  css  js  c++  java
  • 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)
    odejs
    ode_modules
    pm,执行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爱爱爱");
  • 相关阅读:
    嵌入式Linux系统移植(二)——交叉编译工具集
    嵌入式linux系统移植(一)
    C语言常用关键语法精华总结
    ARM汇编常用指令
    嵌入式Linux系统移植——uboot常用命令
    VHDL的参数写在一个vhd文件里
    [PAT] 1077 Kuchiguse (20 分)Java
    [PAT] 1073 Scientific Notation (20 分)Java
    [PAT] 1069 The Black Hole of Numbers (20 分)Java
    [PAT] 1065 A+B and C (64bit) (20 分)Java
  • 原文地址:https://www.cnblogs.com/yaowen/p/7011599.html
Copyright © 2011-2022 走看看