https://github.com/spm999/jwt-nodejs
Node APi to learn basic use of JWT
https://github.com/spm999/jwt-nodejs
authentication authorization backend expressjs jwt-authentication nodejs
Last synced: 2 months ago
JSON representation
Node APi to learn basic use of JWT
- Host: GitHub
- URL: https://github.com/spm999/jwt-nodejs
- Owner: spm999
- Created: 2024-01-29T08:23:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-03T14:09:46.000Z (over 2 years ago)
- Last Synced: 2025-12-06T18:21:29.150Z (7 months ago)
- Topics: authentication, authorization, backend, expressjs, jwt-authentication, nodejs
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# JWT Authentication with Express and Node
This is a simple Node.js and Express application demonstrating JWT (JSON Web Token) authentication. The application includes user login functionality, token generation, and a protected route that requires a valid JWT for access.
## Installation
1. **Clone this repository.**
```bash
git clone https://github.com/spm999/JWT-Nodejs.git
## Installation
1. **Navigate to the project directory.**
```bash
cd JWT-Nodejs
```
2. **Install dependencies.**
```bash
npm install
```
## Usage
1. **Start the server.**
```bash
npm start
```
2. **Access the server at [http://localhost:3000](http://localhost:3000).**
## Endpoints
### User Login
- **URL:** `/login`
- **Method:** `POST`
- **Description:** Allows users to log in and obtain a JWT token.
- **Request Body:** Should include a JSON object with `username` and `password`.
- **Response:** Returns a JWT token if the login is successful.
### Protected Route
- **URL:** `/protected`
- **Method:** `GET`
- **Description:** A protected route that requires a valid JWT for access.
- **Authorization Header:** Should include a Bearer token obtained during login.
- **Response:** Returns a message indicating successful access to the protected route if the token is valid.
## JWT Authentication
The application uses a simple in-memory user database and a secret key for JWT signature. In a real-world scenario, replace the in-memory database with a proper database, and keep the secret key secure.
## Contributing
Feel free to contribute to this project by opening issues or submitting pull requests.