The tutorial
The above diagram shows the structure of the api server. You may ask why we separate the controller and service into 2 modules. The functions in the service module are reusable, so we create the controller module as a proxy to split the business logic out.
Here shows how you can prepare and use the nodemon package.
You will need the cors package for the cross origin enable. This is important for different origin referencing. This is usually happen when your service need to get data from other origin / domain.
# in case you want pnpm $ wget -qO- https://get.pnpm.io/install.sh | sh - # or $ curl -fsSL https://get.pnpm.io/install.sh | sh - # important commands in the tutorial $ npm init $ npm install express dotenv $ node index.js # suppose you have express server defined in index.js $ npm install -D nodemon # with the dev dependence installed, we no need to restart the server after code changed # you need to update the package.json so that you can use nodemon to run your server $ node run dev # now it will run your server by nodemon $ npm install cors # for cross origin enable $ npm install mongoose # for mongodb $ npm install @hapi/joi # library for user input validation $ npm install jsonwebtoken # user login related $ npm install swagger-ui-express yamljs # so that you can have a ui showing all the api end-points
Common development issues
- How to define date input range validation. link
Reference
[1]: Swagger Editor. (n.d.). https://editor.swagger.io/
[2]: The online course. https://www.udemy.com/course/nodejs-rest-api-jwt-security-mongodb-complete-guide/
[3]: auth0.com. (n.d.). JWT.IO. JSON Web Tokens - jwt.io. https://jwt.io/
[4]: Source code. GitHub. https://github.com/SulfredLee/DailyProblem/tree/master/nodejs/udemy_tutorial_001




Comments
Post a Comment