码迷,mamicode.com
首页 > 其他好文 > 详细

npm 安装相关环境及测试

时间:2014-04-29 16:31:45      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   文件   

0、npm 命令

mamicode.com,码迷
C:\Users\Carrie>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
mamicode.com,码迷

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\node_modules下看到express(失败的文件夹)/express-generator 、 jade、 mysql 、.bin这4个文件夹,并且.bin中应该有jade 和jade.cmd。

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

 

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

express myapp

查看nodejs\myapp下的文件结构

$ 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

mamicode.com,码迷
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!");
mamicode.com,码迷

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

打开http://127.0.0.1:8888/

出现:Hello World

npm 安装相关环境及测试,码迷,mamicode.com

npm 安装相关环境及测试

标签:style   blog   http   java   color   文件   

原文地址:http://www.cnblogs.com/la-isla-bonita/p/3699459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!