zoukankan      html  css  js  c++  java
  • node.js 创建第一个web应用

    安装node.js
     
    从http://nodejs.org/ 下载安装程序进行安装。
    安装后从开始菜单启动: Node.js command prompt
     
     
    安装web开发框架Express
     
    如果需要代理访问网络,先用下面的命令设置代理:
    > npm config set proxy=http://192.168.1.1:8080

    运行下面命令进行安装express:

    > npm install express
     
    执行下面命令,安装可执行程序:
    > npm install -g express-generator@3
     
    查看express用法:
    > express --help

      Usage: express [options] [dir]

      Options:

        -h, --help          output usage information
        -V, --version       output the version number
        -e, --ejs           add ejs engine support (defaults to jade)
        -H, --hogan         add hogan.js engine support
        -c, --css   add stylesheet support (less|stylus|compass) (defaults to plain css)
        -f, --force         force on non-empty directory
     
     
    创建web应用
     
    创建应用easy:
    > express  --ejs  easy

       create : easy
       create : easy/package.json
       create : easy/app.js
       create : easy/public
       create : easy/routes
       create : easy/routes/index.js
       create : easy/routes/user.js
       create : easy/views
       create : easy/views/index.jade
       create : easy/views/layout.jade
       create : easy/views/error.jade
       create : easy/bin
       create : easy/bin/www
       create : easy/public/images
       create : easy/public/javascripts
       create : easy/public/stylesheets
       create : easy/public/stylesheets/style.css

       install dependencies:
         $ cd easy && npm install


       run the app:
         $ DEBUG=my-application ./bin/www

    根据上述提示完成easy安装
    > cd easy && npm install
     
     
    启动服务
    追加app.listen(3000); 到easy 目录下app.js文件:
    app.use(app.router);
    app.listen(3000);
    console.log("web server started at port:3000, access now: http://localhost:3000/");
     
    用node运行  app.js:
    > node app.js
     
    接下来, 打开浏览器, 输入地址 http://localhost:3000 , 你就可以看到一个简单的 Welcome
    to Express 页面了:
          node.js <wbr>创建第一个web应用
     
    或者不修改app.js用下面命令启动应用:
    >npm start

    > application-name@0.0.1 start C:easy
    > node ./bin/www
  • 相关阅读:
    7月的尾巴,你是XXX
    戏说Android view 工作流程《下》
    “燕子”
    Android开机动画bootanimation.zip
    戏说Android view 工作流程《上》
    ViewController里已连接的IBOutlet为什么会是nil
    My first App "Encrypt Wheel" is Ready to Download!
    iOS开发中角色Role所产生的悲剧(未完)
    UIScrollView实现不全屏分页的小技巧
    Apple misunderstood my app,now my app status changed to “In Review”
  • 原文地址:https://www.cnblogs.com/itman70s/p/nodejs.html
Copyright © 2011-2022 走看看