zoukankan      html  css  js  c++  java
  • npm 安装相关环境及测试

    0、npm 命令

    C:UsersCarrie>npm express
    
    Usage: npm <command>
    
    where <command> is one of:
        add-user, adduser, apihelp, author, bin, bugs, c, cache,
        completion, config, ddp, dedupe, deprecate, docs, edit,
        explore, faq, find, find-dupes, get, help, help-search,
        home, i, info, init, install, isntall, issues, la, link,
        list, ll, ln, login, ls, outdated, owner, pack, prefix,
        prune, publish, r, rb, rebuild, remove, repo, restart, rm,
        root, run-script, s, se, search, set, show, shrinkwrap,
        star, stars, start, stop, submodule, t, tag, test, tst, un,
        uninstall, unlink, unpublish, unstar, up, update, v,
        version, view, whoami
    
    npm <cmd> -h     quick help on <cmd>
    npm -l           display full usage info
    npm faq          commonly asked questions
    npm help <term>  search for help on <term>
    npm help npm     involved overview
    

    1、安装express(全局)

    npm install express -g(失败:express -v 报错:express: command not found)

    npm install -g express-generator (成功:$ express -V 显示:4.0.0)

    2、安装jade

    npm install jade

    3、安装mysql

    npm install mysql

    完毕后可以在nodejs ode_modules下看到express(失败的文件夹)/express-generator 、 jade、 mysql 、.bin这4个文件夹,并且.bin中应该有jade 和jade.cmd。

    在nodejs下也会出现express.cmd(npm.cmd也在那里)。

    4、在nodejs文件夹下创建一个项目myapp

    express myapp

    查看nodejsmyapp下的文件结构

    $ ls
    app.js  bin  package.json  public  routes  views

     

    5、复制node_modules到myapp下面(这个每次建一个项目都需要复制一次吗?)

    参见:http://blog.csdn.net/lovesomnus/article/details/22731771

    环境搭建到此完工,下面做一个demo测试!

    在myapp下新建helloworld.js

    var http = require("http");
    http.createServer(function(request, response) {  
        response.writeHead(200, {"Content-Type": "text/plain"});  
        response.write("Hello World");  
        response.end();
    }).listen(8888);
    console.log("nodejs start listen 8888 port!");

    Carrie@CARRIE-PC /c/Program Files/nodejs/myapp
    $ node helloworld.js
    nodejs start listen 8888 port!

    打开http://127.0.0.1:8888/

    出现:Hello World

  • 相关阅读:
    div随意拖动,基于jquery。
    智能社官网顶部导航实现demo
    Notepad++7.4.2的配置使用详情
    ejs模板在express里的默认文件夹路径修改
    web前端-《手机移动端WEB资源整合》——meta标签篇
    npm --save-dev --save 的区别【转载】
    正则表达式处理字符串指定位置插入【高级】
    nodejs里的express自动刷新高级篇【转载】
    webstorm快捷键说明
    js私有作用域(function(){})(); 模仿块级作用域
  • 原文地址:https://www.cnblogs.com/la-isla-bonita/p/3699459.html
Copyright © 2011-2022 走看看