Using Netninja playlist : Node.js Crash Course Tutorial
- nodejs.org/en
- download
- click install
easy huh ?
node -v
to get the node version. So, i did it and got the 14.3.0 version yay !
backend is not only about nodeJS, we actually need a server.js so.. run it run it run it run it ... infinitely ? nop.
We've only made a request "localhost:3k" without receiving a response. Check the server.js
it's aint fun if we always get the same page whatever the url is right ? ===> server.js again..
Status code | Definition |
---|---|
200 | OK |
301 | Resource moved |
404 | Not found |
500 | Internal server error |
Status range | Definition |
---|---|
100 Range | informational responses |
200 Range | success codes |
300 Range | codes for redirects |
400 Range | user or client error |
500 Range | server error |
Here we can search for whatever package we need I installed nodemon because it helps us reload the server without Ctrl-C it each time we change our file and run it again
A package.json file is needed if we're using 3rd party packages which we definitely going to use, soo.. let's run this command :
npm init
So yea, i installed a gitignore extension on Vscode (id : codezombiech.gitignore) so that it helps me ignore some people euh.. directories and/or files since i'm new to nodejs and i don't really know what should i keep and not..
Impressive, i've just knew that i don't have to push a node_modules folder, but the server wouldn't load without it. To do so, we need to run :
npm install
npm install express --save
To inject dynamic data to our html, we use View/Template Engines
ejs The chosen one npm install ejs
It means anything (any code obviously) that happens between the Request and Response in the server.
- Logger middleware to log details of every request. morgan
- Authentication check middleware for protected routes.
- Middleware to parse JSON data from requests.
- Return 404 pages.
- ...
The most innovative cloud database service on the market, ...
To connect to the db, we'll use Mongoose (= an ODM library)
npm install mongoose
Mongoose Schema | Mongoose Model |
---|---|
Define the structure of the document | provides an interface which communicate with a db collection |
Type | Usage |
---|---|
Get | requests to get a resource |
Post | requests to create a new data |
Delete | requests to delete data |
Put | requests to update data |
We can have the same route with different request type
= Variables that can change in a route/:param
To split our routes into different files and manage them in small group of routes
Model, View, Controller, it's a way of structuring our code & files and it keeps the code more modular, reusable and easier to read
VID10 & VID11 tutorials are applied in VID09