Trên GitHub, dipakkr/node-auth đã đạt 88 sao, nhóm API, ngôn ngữ JavaScript. Implementing Authentication in NodeJS With Express and JWT - CodeLab #1
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
I am starting a CodeLab series in which I will building something cool and sharing with the community.
Today, We are going to implement Authentication API in Node using JWT, express, and MongoDB.
I advise you to follow the table of content and don't miss any steps. I will provide the full app code link at the end.
Table of Content
1. Introduction
2. Prerequisites
3. Tools and Packages Required
4. Initiate Project
5. Setup MongoDB Database
6. Configure User Model
7. User Signup
8. User Login
9. Get LoggedIn User
10. Conclusion
1. Introduction
User Authentication contains various steps, please checkout this flowchart to know more. We will be using this flow to build authentication system in our application.
2. Prerequisites
You should have prior knowledge of javascript basics, nodejs. Knowledge of ES6 syntax is a plus. And, at last nodejs should be installed on your system.
3. Packages Required
You will be needing these following 'npm' packages.
express
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications
express-validator
To Validate the body data on the server in the express framework, we will be using this library. It's a server-side data validation library. So, even if a malicious user bypasses the client-side verification, the server-side data validation will catch it and throw an error.
body-parser
It is nodejs middleware for parsing the body data.
bcryptjs
This library will be used to hash the password and then store it to database.This way even app administrators can't access the account of a user.
jsonwebtokenjsonwebtoken will be used to encrypt our data payload on registration and return a token. We can use that token to authenticate ourselves to secured pages like the dashboard. There would also an option to set the validity of those token, so you can specify how much time that token will last.
mongoose
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports both promises and callbacks.
4. Initiate Project
We will start by creating a node project. So, Create a new folder with the name 'node-auth' and follow the steps below. All the project files should be inside the 'node-auth' folder.
npm init
npm init will ask you some basic information about project. Now, you have created the node project, it's time to install the required packages. So, go ahead and install the packages by running the below command.
So, the Mongo Server Address(MongoURI) should look like this. Don't try to connect on my MongoURI. It's just a dummy username & password. :smile::smile:
Yayy !! You have successfully created an authentication API in nodejs. Now, You can go ahead and test the /user/me endpoint after logging in.
How to Test the application?
PostMan is required for Testing the API. If you don't have PostMan installed first, install it.
First, register the user or login if you are already registered.
From step 1, you will get a token. Copy that token and put in the header.
Hit Submit
Here is a preview of testing.
10. Conclusion
In this CodeLab - 1, we covered authentication in nodejs using express, jsonwebtoken and MongoDB. We learned about how to write middleware.
Here is the link of full code for this CodeLab: https://github.com/dipakkr/node-auth.
Also, I would love to know what else you want to cover in next CodeLabs.
If you face in problem in running this application, let me know in the comments. Don't forget to give your feedback. Getting feedback helps me improve.
I write about new stuff almost daily. Please follow me on Twitter | Instagram
If you liked the content, Give a star on repo. And, like the post.
dipakkr/node-auth có 88 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/dipakkr/node-auth. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
dipakkr/node-auth có những chủ đề gì?
GitHub topics của dipakkr/node-auth: "api", "authentication", "bcryptjs", "jwt-authentication", "login-signup", "nodejs", "user-authentication". TopGit xếp repo vào nhóm API.
dipakkr/node-auth còn đang phát triển không?
Commit gần nhất trên dipakkr/node-auth là 3.9 năm trước (theo timestamp GitHub). Repo có 42 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
dipakkr/node-auth là gì?
dipakkr/node-auth (dipakkr/node-auth) là dự án JavaScript trên GitHub. Theo mô tả gốc: Implementing Authentication in NodeJS With Express and JWT - CodeLab #1
dipakkr/node-auth so với các dự án API khác thế nào?
dipakkr/node-auth được TopGit xếp vào nhóm API, với 88 sao GitHub và viết bằng JavaScript. Xem trang chủ đề API trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
dipakkr/node-auth viết bằng ngôn ngữ gì?
dipakkr/node-auth chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao dipakkr/node-auth được xếp vào nhóm API?
TopGit xếp dipakkr/node-auth vào nhóm API dựa trên GitHub topics và mô tả của repo (gắn thẻ: "api", "authentication", "bcryptjs"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
node-auth có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về node-auth.