A simple Node.js API service for managing users. This service provides basic CRUD operations for user management with REST endpoints.
- User CRUD operations (Create, Read, Update, Delete)
- User search and pagination
- JWT-based authentication
- Input validation
- External API integration
- Random user generation for testing
- Docker support
- Node.js
- Express.js
- JWT for authentication
- bcrypt for password hashing
- Lodash for utility functions
- Moment.js for date handling
- Axios for HTTP requests
- Validator for input validation
GET /health- Check service health
POST /api/auth/login- User login
GET /api/users- Get all users (with pagination and search)GET /api/users/:id- Get user by IDPOST /api/users- Create new userPUT /api/users/:id- Update userDELETE /api/users/:id- Delete userPOST /api/users/generate-random- Generate random test users
GET /api/external-data- Fetch and process external user data
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
The service will be available at
http://localhost:3000
-
Install dependencies:
npm install --production
-
Start the server:
npm start
-
Build the Docker image:
npm run docker:build
-
Run the container:
npm run docker:run
-
Create a package (.tgz file):
npm run pack
-
Publish to npm registry:
npm run publish
-
Publish to custom registry (e.g., Artifactory):
# First configure your registry npm config set registry <your-artifactory-url> # Then publish npm run publish
-
Or use the helper command for Artifactory:
npm run publish:artifactory
Create a .env file based on .env.example:
PORT- Server port (default: 3000)NODE_ENV- Environment (development/production)JWT_SECRET- Secret key for JWT tokens
Run tests:
npm testcurl -X POST http://localhost:3000/api/users \
-H "Content-Type: application/json" \
-d '{"username": "newuser", "email": "user@example.com"}'curl http://localhost:3000/api/userscurl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "password123"}'MIT