• 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

  • 相关阅读:
    树莓派ZeroW的Python中使用SQLite数据库
    树莓派Python读写配置文件--configparser库
    信号量示例——“生产者——消费者”实验
    互斥锁示例——模拟银行卡取钱
    管道通信(上)
    命名管道——进程通信案例
    文件I/O
    链表习题
    蓝桥杯ACM训练Day4——算法2-8~2-11:链表的基本操作
    C++——类模板几种常见的情况
  • 原文地址:https://www.cnblogs.com/la-isla-bonita/p/3699459.html
Copyright © 2020-2023  润新知