/github-jobs-backend

Primary LanguageJavaScriptMIT LicenseMIT

ExpressJS REST API

REST API with ExpressJS and MongoDB, with JWT authentication.

Setup

Setup environment variables: Create .env file in root of the project and set 3 enviroment variables

PORT = ""

DB_URL = ""

JWT_SECRET = ""

PORT: Port number for local host
DB_URL: MongoDB URL, You can use MongoDB Atlas as database
JWT_SECRET: A random string that will be used for JWT encoding and authentication

API endpoints

Endpoint Purpose Features
/ Homepage None
/api/user/register Registration route that saves information of a new user on the database Duplicate user check, password hashing
/api/user/login Login route that returns token on successful login User existance check, Password match check, JWT Creation
/api/private Example private route that can't be accessed without a token "auth-token" header is required, which means user must be logged in to access this route

Production dependencies

Package Version Purpose
express ^4.17.1 Creating the REST API
jsonwebtoken ^8.5.1 Generating JWT and Authenticating it
mongoose ^6.0.9 Connecting to MongoDB
bcryptjs ^2.4.3 Hashing the password
@hapi/joi ^17.1.1 Schema validation check
dotenv ^10.0.0 Loads environment variables
cors ^2.8.5 enable CORS