This project provides a RESTful API for user management. It allows users to register, login, view their profile and update their information. The API is built using Node.js, Express and MySQL. It utilizes JSON Web Tokens (JWT) for authentication.
To run this project, you will need the following:
- Node.js installed on your system.
- MySQL database server running.
- A MySQL client, such as MySQL Workbench, to create and manage the database.
- Clone the project repository.
git https://github.com/vanshul22/Node-js-Initial-template.git
- Install the dependencies.
npm install
- Create a
.env
file in the project root directory and add the following environment variables:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=password
DB_NAME=test
JWT_SECRET=secret
- Create the database and tables.
mysql -u root -p password -D test < schema.sql
- Server :
(A) Start the Production server.
npm run start
(B) Start the Development Server.
npm run dev
curl -X POST http://localhost:3000/api/users -H "Content-Type: application/json" -d '{"username": "johndoe", "password": "secret"}'
curl -X POST http://localhost:3000/api/users/login -H "Content-Type: application/json" -d '{"username": "johndoe", "password": "secret"}'
curl -X GET http://localhost:3000/api/users -H "Authorization: Bearer <token>" -H "Content-Type: application/json"
curl -X GET http://localhost:3000/api/users/1 -H "Authorization: Bearer <token>" -H "Content-Type: application/json"
curl -X PUT http://localhost:3000/api/users/1 -H "Authorization: Bearer <token>" -H "Content-Type: application/json"
curl -X DELETE http://localhost:3000/api/users/1 -H "Authorization: Bearer <token>" -H "Content-Type: application/json"