A Node.js-based RESTful API for user management with authentication and authorization features. This application provides endpoints for user registration, login, profile management, and more.
- User registration with email and password
- User authentication using JWT (JSON Web Tokens)
- Password hashing using bcrypt
- Input validation and error handling
- Logging system
- Environment variable configuration
- Database integration with Sequelize ORM
- Node.js (v14 or higher)
- npm (Node Package Manager)
- MySQL/PostgreSQL/SQLite (or any database supported by Sequelize)
- Git (for version control)
-
Clone the repository
git clone <repository-url> cd UserManagement
-
Install dependencies
npm install
-
Set up environment variables
- Copy
.env.exampleto.env - Update the database connection details and other environment variables in
.env
cp .env.example .env
- Copy
-
Database setup
- Create a new database in your preferred database server
- Update the database configuration in
config/database.jsif needed - Run migrations:
npx sequelize-cli db:migrate
-
Start the development server
npm start
The server will start on
http://localhost:3000by default.
POST /api/auth/register- Register a new userPOST /api/auth/login- User loginPOST /api/auth/refresh-token- Refresh access tokenPOST /api/auth/logout- User logout
GET /api/users- Get all users (Admin only)GET /api/users/me- Get current user profileGET /api/users/:id- Get user by IDPUT /api/users/me- Update current user profileDELETE /api/users/me- Delete current user account
Create a .env file in the root directory with the following variables:
NODE_ENV=development
PORT=3000
DB_HOST=localhost
DB_USER=your_db_user
DB_PASS=your_db_password
DB_NAME=user_management
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=24h
UserManagement/
├── bin/ # Application startup
├── config/ # Configuration files
├── controllers/ # Route controllers
├── middleware/ # Custom middleware
├── models/ # Database models
├── public/ # Static files
├── routes/ # Route definitions
├── utils/ # Utility classes and functions
├── .env # Environment variables
├── .gitignore # Git ignore file
├── app.js # Express application
└── package.json # Project metadata and dependencies
npm run devnpm testnpm run lintnpm run buildnpm start- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please contact the development team or open an issue in the repository.