0、npm 命令node
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
一、安裝express(全局)mysql
npm install express -g(失敗:express -v 報錯:express: command not found)sql
npm install -g express-generator (成功:$ express -V 顯示:4.0.0)express
二、安裝jadenpm
npm install jadejson
三、安裝mysqlapi
npm install mysqlapp
完畢後能夠在nodejs\node_modules下看到express(失敗的文件夾)/express-generator 、 jade、 mysql 、.bin這4個文件夾,而且.bin中應該有jade 和jade.cmd。測試
在nodejs下也會出現express.cmd(npm.cmd也在那裏)。ui
四、在nodejs文件夾下建立一個項目myapp
express myapp
查看nodejs\myapp下的文件結構
$ ls
app.js bin package.json public routes views
五、複製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