Coder Social home page Coder Social logo

gmatieso / node-express-jwt-auth Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 2.0 302 KB

how to implement an authentication system using Node.js, Express, MongoDB & JSON web tokens (JWT).

Home Page: https://node-express-jwt-auth-8r5r.onrender.com/

JavaScript 50.55% CSS 15.36% EJS 34.09%

node-express-jwt-auth's Introduction

Full-Stack Node.js Application with Express Backend, MongoDB, and JWT Authentication

Overview

This repository contains a full-stack Node.js application with Express.js for the backend, MongoDB as the database, and JWT (JSON Web Token) authentication. The frontend is also built using Express to serve static files.

Features

JWT Authentication: Implements secure user authentication using JSON Web Tokens. Express.js Backend: A robust backend framework with routing and middleware support. MongoDB Integration: Utilizes MongoDB as the database for data storage. Frontend with Express: Express serves static files for the frontend interface. Modular Structure: Codebase is organized into modules for easy maintenance and scalability.

Prerequisites

Before running the application, ensure you have the following installed:

Node.js and npm MongoDB Git (optional) Getting Started Clone the Repository:

[email protected]:Gmatieso/node-express-jwt-auth.git
cd node-express-jwt-auth

Install Dependencies:

npm install

Configure Environment Variables:

Create a .env file in the root directory with the following variables:

env

PORT=3000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key

Configure the Database:

Create a MongoDB database and obtain the connection URI. Update the config/db.js file with your MongoDB URI. Run the Application:

nodemon app

The application will be accessible at http://localhost:3000.

Project Structure

Backend (Node.js/Express)

The backend code is in the backend directory. Entry point: backend/index.js Frontend (Express for Static Files)

Frontend code and static files are in the frontend directory. Entry point: frontend/index.html Database (MongoDB)

MongoDB setup and schema are in the db directory. API Endpoints POST /api/register

Registers a new user. Request Body: json

{
  "username": "yourusername",
  "password": "yourpassword"
}

POST /api/login

Logs in an existing user and generates a JWT token. Request Body: json

{
  "username": "yourusername",
  "password": "yourpassword"
}

GET /api/profile

Retrieves the user's profile information. Requires a valid JWT token.

Screenshot!

image image

Get your live link here!

https://node-express-jwt-auth-8r5r.onrender.com/

Contributing

Contributions are welcome! Please follow the contribution guidelines when submitting pull requests.

License

This project is licensed under the MIT License.

Contact

For any inquiries or feedback, please contact the project maintainer:

Name: Geoffrey Matieso Email: [email protected] Feel free to explore and enhance this full-stack application as per your project requirements. Happy coding!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.