nodejs-express

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:

  1. express: web framework
  2. express-session: session middleware
  3. connect-mongo: Store the session in mongodb and use it with express-session
  4. connect-flash: Middleware for page notification prompts, based on session implementation
  5. ejs: template
  6. express-formidable: Upload middleware for receiving forms and files
  7. config-lite: read configuration file
  8. marked: markdown parsing
  9. moment: time format
  10. mongolass: mongodb driver
  11. objectid-to-timestamp: Generate timestamp based on ObjectId
  12. sha1: sha1 encryption for password encryption
  13. winston: log
  14. 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'}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326611048&siteId=291194637