I am newbie in coding and this is my first project. I would be glad to any advices 😄.
To get the Node server rinnung locally:
- Clone this repo
npm install
to install all required dependencies- Install MongoDB Community Edition and run it with
mongod
- Rename
.env.sample
to.env
, and enter your jwt secret and mongodb connection uri npm run dev
to start the local server
- express - The server for handling and routing HTTP requests
- express-jwt - Middleware for validating JWT auth
- jsonwebtoken - The jwt generator used by auth
- mongoose - For modeling and mapping MongoDB data to javascript
- passport - For handling auth
- nanoid - For generating url-frendly id stings
index.js
- The entry point to app, defines express server and create connection to MongoDB using mongoose. It also requires config, models and routes.config/
- The folder contains configuration for passportroutes/
- The folder contains the route definitions to app API.models/
- The folder contains the schemas definitions for mongoose modelsmiddlewares/
- The folder contains the express-jwt middlewares for auth
Requests are authenticated using the Authorization
header with a valid JWT. There're two express middlewares in middlewares/auth.js
that used to authenticate requests. The required
middleware configures the express-jwt
middleware using app's secret and will return a 401 status code if the request cannot be authenticated. The payload of the JWT can then be accessed from req.payload
in the endpoint. The optional
middleware configures the express-jwt
in the same way as required
, but will not return a 401 status code if the request cannot be authenticated.