This project is a nodejs backend built for MERN (MongoDB, Express.js, React.js, Node.js) stack. It provides user authentication functionality, allowing users to sign up, sign in, and access protected routes using JSON Web Tokens (JWT).
- User registration (Sign Up)
- User authentication (Sign In)
- Access control with JWT
- Protected routes for authenticated users
- Password hashing with bcrypt.js
- MongoDB database integration with Mongoose ODM
- MongoDB: A NoSQL database for storing user data.
- Express.js: A backend web application framework for Node.js.
- Node.js: A JavaScript runtime environment for executing server-side code.
- JWT (JSON Web Tokens): A compact, URL-safe means of representing claims to be transferred between two parties.
- bcrypt.js: A library to help hash passwords securely.
-
Clone the repository:
git clone https://github.com/HasancanCakicioglu/mern-auth-backend.git
-
Navigate to the project directory:
cd mern-auth-backend
-
Install dependencies for the backend:
npm install
-
Set up environment variables:
- Create a
.env
file in the root directory. - Define the following environment variables:
MONGODB_URI=<your_mongodb_uri> JWT_SECRET=<your_jwt_secret> PORT=<your_port>
- Create a
-
Start the development server:
npm run dev
-
Access the application in your browser at
http://localhost:3000
.
- Register a new user by providing a username, email, and password.
- Sign in with your registered email and password to access protected routes.
- After signing in, you'll receive a JWT token, which you can use to access protected routes.
- Access protected routes by including the JWT token in the request headers (e.g.,
Authorization: Bearer <token>
).
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/my-feature
). - Make your changes and commit them (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/my-feature
). - Create a new pull request.
This project is licensed under the MIT License.