First, Node + Express Environment Construction
0, go to node website to download and install node, if you install NPM and node, then install the Global express,-g Global installation
NPM Install Express –g
1. Then use Express to create the project, Command: Express project name
Initialize a node project note that the default page template here is jade.
Most small projects use the Ejs template, so use Express to create a Ejs template node project with the command EXPRESS-E project name
EXPRESS-E Project Name
2, the following content is created to create a successful
If EXPRESS–V (uppercase) error
There are two possibilities: ① installing node in the second step does not add an environment variable, which can be solved by adding the environment variable to node.
②express 4.x version of the command tool, you need to install a command tool, execute the command "NPM install-g Express-generator" After the completion of the test.
Install dependencies Here's to tell us to go into the project file to introduce a third-party module
How the run the app starts this project
Command as shown
3, below we install the third-party module into the project directory
Install
4. Project Structure
App.js main file
Bin is the startup file
Node_modules for third-party modules
Public is a resource file [frontend]
Routes for routing files [background]
views as view files [front end]
PS: This project is currently an empty project, with a simple example
5, run the example, start the project
NPM start
As for why the NPM Start command, look at Package.json.
Here is the command for the start command and the corresponding boot file, which is the NPM start equivalent to node./BIN/WWW, which is all right to start.
6. Open Bin/www
Here in fact to see or to change the main is the port number
Can artificially modify the port number, currently the default is 3000
7, understand here after we open the URL http://127.0.0.1:3000/or http://localhost:3000/
You can see a simple example.
At this point, Node + Express installation is complete.
Reprint Please specify: http://www.cnblogs.com/zhangmingze/p/4995818.html
node. js + Express + Mongodb Development Build personal website (i)