Node.js backend for Project 786 Flutter mobile application.
- 🚀 RESTful API with Express.js
- 📦 MongoDB Atlas database integration
- 🔐 User authentication endpoints
- ✅ CRUD operations for user management
- 🌐 CORS enabled for mobile apps
- 📝 Comprehensive error handling
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB Atlas - Cloud database
- Mongoose - MongoDB ODM
- Install dependencies:
npm install- Create a
.envfile in the backend directory with your MongoDB connection string:
MONGODB_URI=your_mongodb_connection_string
PORT=3000
- Start the development server:
npm run devOr start the production server:
npm start- Development:
http://localhost:3000 - Production:
https://your-app-name.onrender.com
GET /
Returns API information and available endpoints.
POST /addUser
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com"
}
Success Response (201):
{
"success": true,
"message": "User added successfully",
"data": {
"id": "65f1234567890abcdef",
"name": "John Doe",
"email": "john@example.com",
"createdAt": "2026-02-01T10:30:00.000Z"
}
}GET /users
Success Response (200):
{
"success": true,
"message": "Users retrieved successfully",
"count": 2,
"data": [
{
"_id": "65f1234567890abcdef",
"name": "John Doe",
"email": "john@example.com",
"createdAt": "2026-02-01T10:30:00.000Z",
"updatedAt": "2026-02-01T10:30:00.000Z"
}
]
}POST /login
Content-Type: application/json
{
"email": "john@example.com"
}
Success Response (200):
{
"success": true,
"message": "Login successful",
"data": {
"id": "65f1234567890abcdef",
"name": "John Doe",
"email": "john@example.com",
"createdAt": "2026-02-01T10:30:00.000Z"
}
}PUT /updateUser/:id
Content-Type: application/json
{
"name": "Jane Doe",
"email": "jane@example.com"
}
Success Response (200):
{
"success": true,
"message": "User updated successfully",
"data": {
"id": "65f1234567890abcdef",
"name": "Jane Doe",
"email": "jane@example.com",
"updatedAt": "2026-02-01T11:00:00.000Z"
}
}DELETE /deleteUser/:id
Success Response (200):
{
"success": true,
"message": "User deleted successfully",
"data": {
"id": "65f1234567890abcdef",
"name": "John Doe",
"email": "john@example.com"
}
}All error responses follow this format:
{
"success": false,
"message": "Error description",
"error": "Detailed error message"
}Common Status Codes:
200- Success201- Created successfully400- Bad request (validation error)404- Resource not found409- Conflict (duplicate entry)500- Internal server error
- Push your code to GitHub
- Create a new Web Service on Render.com
- Connect your GitHub repository
- Set the following:
- Build Command:
npm install - Start Command:
npm start - Environment Variables: Add
MONGODB_URIwith your connection string
- Build Command:
- Deploy!
Your API will be available at: https://your-app-name.onrender.com
import 'package:http/http.dart' as http;
import 'dart:convert';
// Base URL
final String baseUrl = 'https://your-app-name.onrender.com';
// Add User
Future<void> addUser(String name, String email) async {
final response = await http.post(
Uri.parse('$baseUrl/addUser'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'name': name, 'email': email}),
);
if (response.statusCode == 201) {
print('User added successfully');
}
}
// Get All Users
Future<List<dynamic>> getUsers() async {
final response = await http.get(Uri.parse('$baseUrl/users'));
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
return data['data'];
}
return [];
}
// Login
Future<Map<String, dynamic>?> login(String email) async {
final response = await http.post(
Uri.parse('$baseUrl/login'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'email': email}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
return data['data'];
}
return null;
}ISC
Project 786 Team