This document provides an introduction and overview of Node.js, including what Node.js is, its architecture and basics, how to write "Hello World" programs in Node.js and Express, how to use modules, errors, middleware, routers, Mongoose and MongoDB for databases, and the MEAN stack. It also describes a tutorial for building a backend API with Node.js, Express, Mongoose and MongoDB.
MIDDLEWARE / STANDARDMODULES body‐parser Parse request body and populate req.body cookie‐parser Parse cookie header and populate req.cookies cors Allow CORS requests errorhandler Send a full stack trace of error to the client. Has to be last express.static Serve static content from the "public" directory (html, css, js, etc.) method‐override Lets you use PUT and DELETE where the client doesn't support it
TUTORIAL / GETTHE PROJECT GET THE PROJECT $gitclonehttps://github.com/fabienvauchelles/stweb-angularjs-tutorial.git $cdstweb-angularjs-tutorial/backend
43.
TUTORIAL / SERVER GETTHE NEXT STEP $gitreset--hardq15 $npminstall CREATE A SERVER Fill backend/app.js
44.
TUTORIAL / FIRSTROUTE GET THE NEXT STEP $gitreset--hardq16 CREATE THE 'FINDALL' ROUTE 1. Create a findAll function (node format) to return a list of article 2. Add findAll to the router 3. Add the articles route to backend/app.js
45.
TUTORIAL / ROUTE'CREATE' GET THE NEXT STEP $gitreset--hardq17 CREATE THE 'CREATE' ROUTE 1. Create a create function (node format) to create an article from req.body 2. Add create to the router (HTTP POST)
46.
TUTORIAL / ROUTE'DELETE' GET THE NEXT STEP $gitreset--hardq18 CREATE THE 'DELETE' ROUTE 1. Create a destroy function (node format) to remove an article (id in the url) 2. Add destroy to the router (HTTP DELETE)
TUTORIAL / MONGOOSE GETTHE NEXT STEP $gitreset--hardq19 IMPORT DATA $mongoimport--dbpostagram--collectionarticles --filearticles-init.json ADD MONGOOSE TO THE PROJECT $npminstallmongoose--save
49.
TUTORIAL / CONNECT GETTHE NEXT STEP $gitreset--hardq20 CONNECT SERVER TO MONGODB Add connect in backend/app.js
50.
TUTORIAL / FINDALL GETTHE NEXT STEP $gitreset--hardq21 USE MONGOOSE FOR FINDALL 1. Comment create & destroy route (and function) 2. Import mongoose with require 3. Replace article static model with a mongoose schema 4. Use mongoose to implement findAll
51.
TUTORIAL / SEARCH GETTHE NEXT STEP $gitreset--hardq22 REPLACE FINDALL BY SEARCH Use a MongoDB filter to search on title. Bonus: filter on description and tags
52.
TUTORIAL / ROUTE'CREATE' GET THE NEXT STEP $gitreset--hardq23 IMPLEMENT CREATE 1. Use mongoose to implement create 2. Uncomment the create route
53.
TUTORIAL / ROUTE'DELETE' GET THE NEXT STEP $gitreset--hardq24 IMPLEMENT DELETE 1. Use mongoose to implement delete 2. Uncomment the delete route