node.js JWT Authentication | WebAPI
Автор: Max(Mamad) Taheri
Загружено: 2023-02-20
Просмотров: 257
node.js JWT Authentication for WebAPI projects + dockerizing the node js project
💻 Completed codes: https://github.com/DevEmpower/auth-js...
In this tutorial, we'll be building a Node.js application with user authentication using JSON Web Tokens (JWT). We'll start by installing and setting up json-server, a popular tool for quickly creating REST APIs. Then, we'll add user authentication to our server by using JWT, which is a widely used method for securing APIs. After that, we'll refactor our server code to make it more maintainable, and finally, we'll dockerize the server. By the end of this tutorial, you'll have a better understanding of how to build and secure JSON servers with user authentication using JWT, and how to containerize them with Docker for easier deployment.
Section 1: Setting up the Project
The first step in building our JSON server is to install and set up json-server. We'll begin by installing it using npm, a package manager for Node.js. Then, we'll create a basic server with sample data to test it out. Next, we'll add user authentication to our server using JWT. We'll install the necessary packages and create endpoints for registration and login. We'll also create a middleware function for verifying JWT tokens to ensure that only authenticated users can access protected routes. To test our authentication system, we'll use Postman.
Section 2: Refactoring the Code
Now that our server is up and running, we'll take a closer look at the code and identify areas that could be improved. We'll discuss the benefits of refactoring code, and explain why it's important to write code that's easy to maintain. Then, we'll make some changes to the server code to make it more modular and easier to read. We'll create separate files for utils and middleware, and use a data folder for storing our data. Finally, we'll test the refactored code to ensure that it's still working as expected.
Section 3: Dockerizing the Server
The next step in our tutorial is to dockerize our server. Docker is a containerization platform that allows us to package our application and its dependencies into a single container, which can be run on any platform that supports Docker. We'll create a Dockerfile for our server, which will specify the base image, set environment variables, copy the server code into the container, and expose the port that the server is listening on. Then, we'll build the Docker image and run the container to test that it's working correctly.
✏️ sections
(00:00:00) Introduction
(00:01:12) Section 1: Setting up the Project
(00:53:52) Section 2: Refactoring the Code
(01:14:49) Section 3: Dockerizing the Server
(01:25:47) Conclusion
🌎 Me:
Telegram: https://t.me/DevEmpower
LinkedIn: / mohammad-taheri1
GitHub: https://github.com/mohammad-taheri1
Medium: / devempower
Portfolio: https://devempower.ir/
💖 Hope you enjoy it 💖
💖 If you loved this node.js WebAPI JWT Authentication tutorial, leave comments, like, and subscribe 💖
💖 You can Buy me a coffee to support: https://www.buymeacoffee.com/DevEmpower 💖
Disclaimer: This video is just a YouTube tutorial for beginners and it is not a commercial code. Use these Codes and functions on your responsibilities. Don’t forget that security is very important in any software and website and you must be aware of any functionality of codes of your projects.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: