Built with Node.js Β· Express Β· MongoDB Β· JWT
Production-ready RESTful CRM backend built with Node.js, Express & MongoDB
NexusCRM is a secure, scalable Customer Relationship Management backend that allows sales teams to manage contacts, track deals through a pipeline, and administer users β all through a clean JSON REST API with JWT-based authentication.
| Layer | Technology | Purpose |
|---|---|---|
| Runtime | Node.js 18+ | JavaScript server environment |
| Framework | Express.js 4.x | HTTP routing & middleware pipeline |
| Database | MongoDB Atlas | Cloud-hosted document storage |
| ODM | Mongoose 7.x | Schema modeling & query builder |
| Auth | JSON Web Tokens | Stateless session management |
| Security | bcryptjs | Password hashing with salt rounds |
| Config | dotenv | Environment variable management |
| Dev Tool | nodemon | Hot-reload during development |
Request flow: Client β CORS/JWT Middleware β Route Controller β Service Logic β MongoDB β JSON Response
nexuscrm-server/
βββ Server.js β Entry point (Express init + DB connect)
βββ .env β Secrets (never commit this)
βββ package.json
β
βββ config/
β βββ db.js β Mongoose connection setup
β
βββ middleware/
β βββ authMiddleware.js β JWT verification for protected routes
β
βββ models/
β βββ User.js β User schema (name, email, passwordHash, role)
β βββ Contact.js β Contact schema (name, email, phone, company)
β βββ Deal.js β Deal schema (title, value, stage, contactRef)
β
βββ routes/
β βββ authRoutes.js β POST /register POST /login
β βββ userRoutes.js β GET PUT DELETE /users/:id
β βββ contactRoutes.js β Full CRUD /contacts
β βββ dealRoutes.js β Full CRUD /deals
β
βββ controllers/
βββ authController.js
βββ userController.js
βββ contactController.js
βββ dealController.js
- Node.js v18+
- npm v9+
- MongoDB Atlas account (or local MongoDB)
# 1. Clone the repo
git clone https://github.com/your-username/nexuscrm-server.git
cd nexuscrm-server
# 2. Install dependencies
npm install
# 3. Setup environment
cp .env.example .env
# β Edit .env with your credentials
# 4. Run in development mode
npm run devExpected terminal output:
[nodemon] 3.0.0
[nodemon] starting `Server.js`
β MongoDB Atlas connected successfully
β Server is running on http://localhost:5000
Create a .env file in the root:
PORT=5000
NODE_ENV=development
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/nexuscrm
JWT_SECRET=your_super_secret_key_minimum_32_characters
JWT_EXPIRES_IN=7d
β οΈ Never commit.envto version control. It is listed in.gitignore.
All routes are prefixed with /api. Protected routes require:
Authorization: Bearer <your_jwt_token>
| Method | Endpoint | Access | Description |
|---|---|---|---|
POST |
/api/auth/register |
π’ Public | Register new user |
POST |
/api/auth/login |
π’ Public | Login & get JWT token |
| Method | Endpoint | Access | Description |
|---|---|---|---|
GET |
/api/users |
π Protected | Get all users |
GET |
/api/users/:id |
π Protected | Get user by ID |
PUT |
/api/users/:id |
π Protected | Update user profile |
DELETE |
/api/users/:id |
π Protected | Delete user |
| Method | Endpoint | Access | Description |
|---|---|---|---|
GET |
/api/contacts |
π Protected | List all contacts |
POST |
/api/contacts |
π Protected | Create a contact |
GET |
/api/contacts/:id |
π Protected | Get contact by ID |
PUT |
/api/contacts/:id |
π Protected | Update contact |
DELETE |
/api/contacts/:id |
π Protected | Delete contact |
| Method | Endpoint | Access | Description |
|---|---|---|---|
GET |
/api/deals |
π Protected | List all deals |
POST |
/api/deals |
π Protected | Create a deal |
GET |
/api/deals/:id |
π Protected | Get deal by ID |
PUT |
/api/deals/:id |
π Protected | Update / move stage |
DELETE |
/api/deals/:id |
π Protected | Delete a deal |
Deal pipeline: lead β proposal β negotiation β closed-won / closed-lost
{
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0ZjFjM2E3ZTJiO...",
"user": {
"_id": "64f1c3a7e2b8d90012af3e11",
"name": "Jane Doe",
"email": "jane@example.com",
"role": "admin",
"createdAt": "2024-08-01T10:30:00.000Z"
}
}[
{
"_id": "64f2a8b1c3e1f70034cd9e21",
"name": "Acme Corporation",
"email": "contact@acme.com",
"phone": "+1-800-555-0100",
"company": "Acme Corp",
"deal": {
"stage": "proposal",
"value": 24000
},
"createdAt": "2024-08-05T08:20:00.000Z"
}
]{
"success": false,
"message": "Not authorized, token missing or invalid"
}{
"success": false,
"message": "User already exists with this email"
}| Threat | Protection |
|---|---|
| Plain-text passwords | bcryptjs with 10 salt rounds β never stored raw |
| Unauthorized access | JWT middleware blocks all protected routes |
| Cross-origin attacks | CORS configured with allowed origins |
| Invalid data | Mongoose schema validation before any DB write |
| Secret exposure | All keys in .env, never hardcoded in source |
1. REGISTER β Password hashed (bcrypt) β User saved in MongoDB
2. LOGIN β Hash compared (bcrypt) β JWT token signed & returned
3. REQUEST β Bearer token in header β JWT middleware verifies
4. EXPIRED β 401 Unauthorized β Client re-authenticates
{
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"mongoose": "^7.0.0"
},
"devDependencies": {
"nodemon": "^3.0.0"
}
}npm start # Production β node Server.js
npm run dev # Development β nodemon Server.js (hot reload)MIT Β© 2024 NexusCRM
Built with Node.js Β· Express Β· MongoDB Β· JWT Β· bcrypt
