Node.js + Express backend for user authentication and management with MongoDB.
- User registration, login, password reset
- User profile management (get and update)
- Admin functionality to list all users
- JWT authentication and role-based authorization
- Password hashing with bcrypt
- Input validation and sanitization
- Security best practices with helmet and cors
- Global error handling
- Environment variable management with dotenv
- Render.com deployment ready
Create a .env file in the root directory with the following variables:
PORT=5000
DB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
- Install dependencies:
npm install- Start the server:
npm startThe server will run on http://localhost:5000 (or the port specified in .env).
- URL:
/api/register - Method: POST
- Body:
{
"name": "John Doe",
"email": "[email protected]",
"password": "password123"
}- URL:
/api/login - Method: POST
- Body:
{
"email": "[email protected]",
"password": "password123"
}- URL:
/api/profile/update - Method: PUT
- Headers:
Authorization: Bearer <token> - Body (any of the fields can be updated):
{
"name": "John Updated",
"email": "[email protected]",
"password": "newpassword123"
}- URL:
/api/admin/users - Method: GET
- Headers:
Authorization: Bearer <admin_token>
- Push your project to GitHub.
- Create a new Web Service on Render.com.
- Connect your GitHub repository.
- Set the environment variables on Render:
DB_URIJWT_SECRETPORT
- Use the following build and start commands:
- Build Command:
npm install - Start Command:
npm start
- Build Command:
- Deploy and get your live API URL.
This project uses modern ES6 syntax and follows best practices for production-ready Node.js applications.