one. Installation of node environment, reference link: http://975156298.iteye.com/blog/2314388
two. For the installation of mongodb database, refer to the link: http://www.runoob.com/mongodb/mongodb-linux-install.html
three. Installation of express framework.
$ npm install -g express-generator
This makes it possible to create a node project template directly using express.
$ express -e blog
$ cd blog && npm install
The above code can create a node program with name: blog.
Four. Node automatically restarts the program supervisor. Install:
$ npm install supervisor
Fives. The middleware required for a simple node program is as follows:
-
express
: web framework -
express-session
: session middleware -
connect-mongo
: Store the session in mongodb and use it with express-session -
connect-flash
: Middleware for page notification prompts, based on session implementation -
ejs
: template -
express-formidable
: Upload middleware for receiving forms and files -
config-lite
: read configuration file -
marked
: markdown parsing -
moment
: time format -
mongolass
: mongodb driver -
objectid-to-timestamp
: Generate timestamp based on ObjectId -
sha1
: sha1 encryption for password encryption -
winston
: log -
express-winston
: Winston-based logging middleware for express
six. Next, you can develop it based on the node knowledge you have learned directly.
Seven: Description.
Route to get data:
-
req.query
: The querystring in the parsed url, for example?name=haha
, the value of req.query is{name: 'haha'}
-
req.params
: Parse the placeholder in the url, for example/:name
, visit /haha, the value of req.params is{name: 'haha'}
-
req.body
: After parsing the request body, you need to use related modules, such as body-parser , if the request body is{"name": "haha"}
, then req.body is{name: 'haha'}