I. Preparation
Installed Nodejs (NODE,NPM)
Two.
1. Create a workspace:
$ mkdir ~/workspace/nodejs/$ CD ~/workspace/nodejs/$ Pwd/users/vincent/desktop/my/workspace/nodejs
2. Install Express
$ sudo npm install express -g[email protected] /usr/local/lib/node_modules/ express├── [email protected]├── [email protected]├── [email protected]├── [ email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected] ├── [email protected] ([email protected]) ├── [email protected] ([email protected]) ├── [email protected] ([email protected]) ├── [email protected] ([email protected], [email protected]) ├── [email protected] ([email Protected], [email protEcted], [email protected]) ├── [email protected] ([email protected]) └── [ email protected] ([email protected], [email protected])
3. Set up Express project to start the first project
$ express-e Nodejs-demo-bash:express:command not found
I have also been in the pit, looking for the mother looked for a bit, from the results found a more satisfactory result:
1 Express Command not found
Initial operation : Follow the "Nodejs Development Guide" knocking npm install -g express
, installed, on the Linux command line knocking on express --help
the cause of the above.
Workaround : Install a packagenpm install -g express-generator
cause : express3+ has separated the creation of an app into a express-generator, you can't create an app without it
2 express-t Ejs microblog created is not the Ejs template engine but the Jade template engine
Initial action : Follow the Nodejs Development Guide in command-line knocking express -t ejs microblog
is used to create the application, the name of the application is microblog, the template engine is Ejs
What happens : But by looking at the Package.json in the microblog folder, you know that the Ejs template is not created but the Jade template engine
-
workaround : Version different, with the wrong command, should be EXPRESS-E microblog
(-E is the Ejs template)
-
3 node App.js no effect
-
first operation : Follow the Nodejs development guide Tap node app.js at the command line and then use the browser to access the Listening 3000 port
-
< Span style= "FONT-SIZE:18PX;" >: Cannot access page
-
workaround : Version different, with the wrong command, should be NPM start
The above paragraph is obtained from the http://blog.csdn.net/dai_jing/article/details/38087443 place.
After you find the reason, execute the following command:
$ sudo npm install-g express-generator/usr/local/bin/express-/usr/local/lib/node_modules/express-generator/bin /express[email protected]/usr/local/lib/node_modules/express-generator├──[email protected] ([email protected]) └──[ Email protected] ([email protected])
$ express -e nodejs-demo create : nodejs-demo create : nodejs-demo/package.json create : nodejs-demo/app.js create : nodejs-demo/public create : nodejs-demo/public/images create : nodejs-demo/public/javascripts create : Nodejs-demo/public/stylesheets create : nodejs-demo/public/stylesheets/style.css create : nodejs-demo/routes create : nodejs-demo/routes /index.js create : nodejs-demo/routes/users.js create : Nodejs-demo/views create : nodejs-demo/views/index.ejs create : nodejs-demo/views/error.ejs create : nodejs-demo/bin Create : nodejs-demo/bin/www install dependencies: $ cd nodejs-demo && npm install run the app: $ Debug=nodejs-demo ./bin/www
Install dependent packages
$ cd nodejs-demo/$ sudo npm install[email protected] node_modules/ejs[email protected] node_modules/cookie-parser├── [email protected]└── [email protected] [Email protected] node_modules/debug└── [email protected][email protected] node_ modules/serve-favicon├── [email protected]├── [email protected]└── [email protected] ([email protected]) [email protected] node_modules/morgan├── [email protected]├── [email protected]└── [email protected] ([email protected]) [Email protected] node_modules/express├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected] ├── [email protecteD]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected] ([email protected]) ├── [email protected]├── [email protected] ([email protected]) ├── [email protected] ([email protected], [email protected]) ├── [email protected] ([email protected], [email protected], [email protected], [email Protected]) ├── [email protected] ([email protected], [email protected]) └── [email protected] ([email protected]) [email protected] node_modules/body-parser├── [email protected]├── [email protected]├── [email protected]├── [email protected]├── [email protected] ([email protected]) ├── [email protected] ├── [email protected]└── [email protected] ([email protected])
Start the program
$ NPM start> [email protected] start/users/vincent/desktop/my/workspace/nodejs/nodejs-demo> node./bin/www
Also open a terminal test if it starts successfully
$ Curl localhost:3000<! DOCTYPE html>
The contents of this article are recorded according to the instructions in http://blog.fens.me/nodejs-enviroment/.
This link is from: http://blog.fens.me/series-nodejs/
The content in this link is suitable for novice nodejs.
This article is from the "Progressive Birds" blog, please be sure to keep this source http://vincent90.blog.51cto.com/3221926/1584006
Mac Nodejs Learning notes build the first NODEJS development environment