This project is designed to implement a secure Node.js backend application. It features user authentication using JSON Web Tokens (JWT), a simple CRUD API, and file upload and download functionality.
- User Authentication with JWT: Users can register and log in, with the system providing JWT tokens for session management.
- CRUD API: A RESTful API allows for creating, reading, updating, and deleting information from a database.
- File Upload & Download: Users can upload files to the server and retrieve them through secure download links.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Before you begin, ensure you have met the following requirements:
- Node.js: You can download it from Node.js official website.
- npm: Comes with Node.js. After installing Node.js, run
npm -v
in a terminal to ensure npm is installed. - MongoDB Database: Set up a MongoDB instance either locally or use a cloud service like MongoDB Atlas.
A step-by-step series of examples that tell you how to get a development environment running:
Clone the repository:
git clone https://github.com/akash-tk/AuthCRUDVault.git
cd AuthCRUDVault
Install the necessary node modules:
npm install
To get your application running, you need to set up your environment variables:
- Create a
.env
file in the root directory of your project. - Add the following variables to the
.env
file, replacing the placeholders with your actual data:
PORT=3000
JWT_SECRET=your-jwt-secret
REFRESH_TOKEN_SECRET=your-refresh-token-secret
MONGODB_URI=mongodb+srv://your-db-connection-string
Start the server:
node server.js
The server will start on port 3000 or the next available port.
You can find the Postman collection in /Postman directory to easily test the API endpoints.
You can find the Screenshots of the implementation in /Screenshots directory.
-
Starting the server:
- Run
npm start
. - This command will start the server at the specified port, defaulting to 3000.
- Run
-
Register a new user:
- Send a POST request to
/register
with a JSON body containingusername
andpassword
.
- Send a POST request to
-
Login:
- Send a POST request to
/login
withusername
andpassword
to receive a JWT token.
- Send a POST request to
-
CRUD Operations:
- Send a POST to
/api/users
to create a new user. - Send a GET to
/api/users
to read available users. - Send a PUT to
/api/users/:id
to update an existing user. - Send a DELETE to
/api/users/:id
to delete a user.
- Send a POST to
-
File Upload:
- Send a POST request to
/api/upload
with a file in the form-data to upload a file.
- Send a POST request to
-
File Download:
- Access
/api/download/:filename
to download the corresponding file.
- Access
File uploads are validated for type and size. JWTs ensure secure communication with the API endpoints. Always keep your dependencies up to date to mitigate vulnerabilities.