| layout | default |
|---|---|
| title | Local Development |
| nav_order | 3 |
{: .no_toc }
{: .no_toc .text-delta }
- TOC {:toc}
This guide explains how to set up and run the MEAN Stack Contacts application locally without Docker.
Before getting started, make sure you have the following installed:
- Node.js (LTS version (22+) recommended): Download Node.js{:target="_blank"}
- npm (comes with Node.js)
- MongoDB (Community Edition): Download MongoDB{:target="_blank"}
- Angular CLI (optional but recommended):
npm install -g @angular/cli
- Install MongoDB Community Edition following the official instructions{:target="_blank"} for your operating system.
- Start the MongoDB service:
- Windows: The MongoDB service should start automatically
- macOS:
brew services start mongodb-community - Linux:
sudo systemctl start mongod
-
Create a new database:
mongosh use mean-contacts
-
Create an admin user:
db.createUser({ user: "admin-user", pwd: "admin-password", roles: [{ role: "readWrite", db: "mean-contacts" }] })
-
Create a test user:
db.users.insertOne({ username: "nitin27may@gmail.com", email: "nitin27may@gmail.com", password: "$2a$10$nc0yO2eeCDOLg6sObsAHfuXQY8NnCrhHz5GbkmPYsAGLsQoSZa.qm", // P@ssword#321 firstName: "Nitin", lastName: "Singh", create_date: new Date() })
-
Add sample contacts:
db.contacts.insertMany([ { firstName: "Nitin", lastName: "Singh", mobile: "9876543243", email: "nitin27may@gmail.com", city: "Mumbai", postalCode: "421201", create_date: new Date() }, { firstName: "Sachin", lastName: "Singh", mobile: "9876540000", email: "sachin@gmail.com", city: "Pune", postalCode: "421201", create_date: new Date() }, { firstName: "Vikram", lastName: "Singh", mobile: "9876541111", email: "vikram@gmail.com", city: "Pune", postalCode: "421201", create_date: new Date() } ])
-
Navigate to the API directory:
cd mean-docker/api -
Install dependencies:
npm install
-
Create a
.envfile based on.env.example:example`:
cp .env.example .env
PORT=3000 SECRET=your_jwt_secret_key MONGO_DB_USERNAME=admin-user MONGO_DB_PASSWORD=admin-password MONGO_DB_HOST=localhost MONGO_DB_PORT=27017 MONGO_DB_PARAMETERS=?authSource=admin MONGO_DB_DATABASE=mean-contacts -
Start the API in development mode:
npm run dev:watch
The API will be available at http://localhost:3000/api.
-
Navigate to the frontend directory:
cd mean-docker/frontend -
Updated the API endpoint in environment.ts
export const environment = { production: false, apiEndpoint: 'http://localhost:3000/api', // updating this angular: 'Angular 21', bootstrap: 'Bootstrap 5', expressjs: 'Express.js 4.21', mongoDb: 'MongoDB 7.0',
};
3. Install dependencies:
```bash
npm install
- Start the development server:
npm run serve
The frontend will be available at http://localhost:4200.
- Open your browser and navigate to
http://localhost:4200 - Log in with the test credentials:
- Username:
nitin27may@gmail.com - Password:
P@ssword#321
- Username:
- After successful login, you'll be redirected to the home page
- Navigate to Contacts to view, add, edit, and delete contacts
-
You can debug the Node.js backend using:
- Visual Studio Code's debugger (launch configuration is included)
- Chrome DevTools by running:
node --inspect server.js
- Then open
chrome://inspectin Chrome
-
For real-time API testing, use tools like:
- Use the Angular DevTools extension for Chrome
- Use the browser's built-in DevTools (F12)
- Enable source maps in Chrome for better debugging
If you encounter issues connecting to MongoDB:
- Ensure MongoDB is running:
mongosh - Check your firewall settings
- Verify credentials in the
.envfile - Try connecting manually:
mongosh mongodb://admin-user:admin-password@localhost:27017/mean-contacts?authSource=admin
If you encounter CORS errors:
- Ensure the API is running on the expected port (3000)
- Check the frontend is correctly proxying requests to the API
If authentication fails:
- Check the SECRET in your
.envfile - Ensure the user exists in the database with the correct credentials
- Verify the token is being sent correctly in the Authorization header
cd mean-docker/api
npm run buildcd mean-docker/frontend
npm run build:prodThe frontend build will create a production-ready bundle in the dist/ directory, which can be deployed to any static hosting service or server.