A Node.js + Express.js REST API for managing ideas, enhanced with advanced database operations and JWT authentication.
Built with SQLite/PostgreSQL, bcryptjs, and jsonwebtoken.
- User registration & login with JWT authentication
- CRUD operations for ideas
- Advanced querying: filtering, sorting, pagination
- User-specific ideas (if
userIdis linked) - Secure endpoints with authentication middleware
- Prepared for deployment using PM2
- Includes unit & integration tests
- Scalability strategies documented
- Node.js
- Express.js
- SQLite / PostgreSQL
- bcryptjs
- jsonwebtoken (JWT)
- dotenv
- Jest + Supertest (for testing)
- PM2 (for deployment)
. ├── server.js # Main entry point ├── authMiddleware.js # JWT authentication middleware ├── routes/ # Route definitions │ ├── ideas.js │ └── users.js ├── db/ # Database setup & migrations ├── utils/ # Helper functions (e.g., password hashing) ├── tests/ # Unit & integration tests ├── ecosystem.config.js # PM2 config for deployment ├── .env # Environment variables └── README.md
git clone https://github.com/koussay0/Node.js-REST-API-with-JWT-authentication-advanced-querying-and-deployment-setup
cd Node.js-REST-API-with-JWT-authentication-advanced-querying-and-deployment-setupnpm install
PORT=3000
JWT_SECRET=your_super_secret_jwt_key
DB_URL=sqlite://ideas.db # or postgres://user:pass@localhost:5432/dbname
- Start development server:
npm start
POST /api/register → Register a new user
POST /api/login → Login user & return JWT
GET /api/ideas → Get all ideas (supports filtering, sorting, pagination)
POST /api/ideas → Create a new idea (requires JWT)
PUT /api/ideas/:id → Update an idea (requires JWT, owner only)
DELETE /api/ideas/:id → Delete an idea (requires JWT, owner only)
- Filtering: /api/ideas?status=Concept
- Sorting: /api/ideas?sort=title&order=asc
- Pagination: /api/ideas?_limit=10&_page=1
JWT tokens are returned on login
Add token to requests in the Authorization header:
Authorization: Bearer YOUR_JWT_TOKEN
npm install --save-dev jest supertest
npm test
✅ Unit tests for utility functions (e.g., password hashing) ✅ Integration tests for: GET /api/ideas POST /api/register POST /api/login POST /api/ideas (authenticated request)
npm install -g pm2
pm2 start ecosystem.config.js
module.exports = {
apps: [{
name: "secure-ideas-api",
script: "./server.js",
instances: "max", // maximize CPU usage
exec_mode: "cluster",
watch: true,
env: {
NODE_ENV: "development",
PORT: 3001
},
env_production: {
NODE_ENV: "production",
PORT: 80
}
}]
};
Thanks for USAM for giving us the chance for this learning opportunity.