安装4.x版本的express开发框架
错误版本(未更新前的安装方法,更新后就不是这么安装了,好多网上的教程还是这种方法,所以这里先写明了,旧版这里是可以通过的,但是新版4.x就不行了,请用分割线下边的方法)
[root@BobServerStation local]# yum -y install gcc gcc-c++ openssl-devel
[root@BobServerStation local]# wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz
[root@BobServerStation node-v0.10.24]# ./configure --prefix=/usr/local/node
[root@BobServerStation node-v0.10.24]# vim /etc/profile
[root@BobServerStation node-v0.10.24]# node -v
v0.10.24
[root@BobServerStation node-v0.10.24]# node
> console.log(”Hello NodeJS, I'm Bob.Z“);
Hello NodeJS, I'm Bob.Z
undefined
>
[root@BobServerStation local]# npm install express -g
[root@BobServerStation local]# express DemoApp
[root@BobServerStation local]# cd DemoApp
[root@BobServerStation DemoApp]#
[root@BobServerStation local]# cd DemoApp
[root@BobServerStation DemoApp]# npm install
[root@BobServerStation DemoApp]# node app
Express server listening on port 3000
Express
Welcome to Express
在官网找到了解决方法是 express 4需要通过 下面的命令安装
npm install -g express-generator
[root@localhost nodejs]# npm install -g express-generator /root/git/nvm/versions/node/v4.2.1/bin/express ->/root/git/nvm/versions/node/v4.2.1/lib/node_modules/express-generator/bin/express express-generator@4.13.1/root/git/nvm/versions/node/v4.2.1/lib/node_modules/express-generator ├── sorted-object@1.0.0 ├── mkdirp@0.5.1(minimist@0.0.8) └── commander@2.7.1(graceful-readlink@1.0.1)
[root@localhost DemoApp]# express -V 4.13.1 [root@localhost DemoApp]# express -h 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) --hbs add handlebars engine support -H,--hogan add hogan.js engine support -c,--css <engine> add stylesheet <engine> support (less|stylus|compass|sass)(defaults to plain css) --git add .gitignore -f,--force force on non-empty directory
[root@localhost nodejs]# express DemoApp create :DemoApp create :DemoApp/package.json create :DemoApp/app.js create :DemoApp/public create :DemoApp/public/javascripts create :DemoApp/public/images create :DemoApp/public/stylesheets create :DemoApp/public/stylesheets/style.css create :DemoApp/routes create :DemoApp/routes/index.js create :DemoApp/routes/users.js create :DemoApp/views create :DemoApp/views/index.jade create :DemoApp/views/layout.jade create :DemoApp/views/error.jade create :DemoApp/bin create :DemoApp/bin/www install dependencies: $ cd DemoApp&& npm install run the app: $ DEBUG=DemoApp:* npm start
[root@localhost nodejs]#cd DemoApp/&& npm install cookie-parser@1.3.5 node_modules/cookie-parser ├── cookie@0.1.3 └── cookie-signature@1.0.6 debug@2.2.0 node_modules/debug └── ms@0.7.1 serve-favicon@2.3.0 node_modules/serve-favicon ├── etag@1.7.0 ├── fresh@0.3.0 ├── ms@0.7.1 └── parseurl@1.3.0 morgan@1.6.1 node_modules/morgan ├── on-headers@1.0.1 ├── basic-auth@1.0.3 ├── depd@1.0.1 └── on-finished@2.3.0(ee-first@1.1.1) express@4.13.3 node_modules/express ├── escape-html@1.0.2 ├── merge-descriptors@1.0.0 ├── cookie@0.1.3 ├── array-flatten@1.1.1 ├── cookie-signature@1.0.6 ├── utils-merge@1.0.0 ├── content-type@1.0.1 ├── methods@1.1.1 ├── vary@1.0.1 ├── etag@1.7.0 ├── path-to-regexp@0.1.7 ├── serve-static@1.10.0 ├── range-parser@1.0.3 ├── content-disposition@0.5.0 ├── fresh@0.3.0 ├── parseurl@1.3.0 ├── depd@1.0.1 ├── qs@4.0.0 ├── proxy-addr@1.0.10(forwarded@0.1.0, ipaddr.js@1.0.5) ├── finalhandler@0.4.0(unpipe@1.0.0) ├── on-finished@2.3.0(ee-first@1.1.1) ├── type-is@1.6.10(media-typer@0.3.0, mime-types@2.1.9) ├── send@0.13.0(destroy@1.0.3, statuses@1.2.1, ms@0.7.1, mime@1.3.4, http-errors@1.3.1) └── accepts@1.2.13(negotiator@0.5.3, mime-types@2.1.9) body-parser@1.13.3 node_modules/body-parser ├── content-type@1.0.1 ├── bytes@2.1.0 ├── depd@1.0.1 ├── qs@4.0.0 ├── on-finished@2.3.0(ee-first@1.1.1) ├── http-errors@1.3.1(statuses@1.2.1, inherits@2.0.1) ├── iconv-lite@0.4.11 ├── type-is@1.6.10(media-typer@0.3.0, mime-types@2.1.9) └── raw-body@2.1.5(unpipe@1.0.0, bytes@2.2.0, iconv-lite@0.4.13) jade@1.11.0 node_modules/jade ├── commander@2.6.0 ├── character-parser@1.2.1 ├── void-elements@2.0.1 ├── mkdirp@0.5.1(minimist@0.0.8) ├── constantinople@3.0.2(acorn@2.7.0) ├── clean-css@3.4.9(commander@2.8.1, source-map@0.4.4) ├── jstransformer@0.0.2(is-promise@2.1.0, promise@6.1.0) ├── transformers@2.1.0(promise@2.0.0, css@1.0.8, uglify-js@2.2.5) ├── with@4.0.3(acorn@1.2.2, acorn-globals@1.0.9) └── uglify-js@2.6.1(async@0.2.10, uglify-to-browserify@1.0.2, source-map@0.5.3, yargs@3.10.0)
root@localhost DemoApp]#npm start >DemoApp@0.0.0 start /root/nodejs/DemoApp > node ./bin/www GET /200382.317 ms -170 GET /stylesheets/style.css 20017.834 ms -111 GET /favicon.ico 40456.666 ms -1015 GET /favicon.ico 40439.911 ms -1015 GET /30458.911 ms -- GET /stylesheets/style.css 3041.839 ms -- GET /30447.751 ms -- GET /stylesheets/style.css 3040.280 ms -- GET /30453.378 ms -- GET /stylesheets/style.css 3040.258 ms --
npm install express --save