How to Set Up a MEAN Stack Development Environment
The MEAN stack is a popular JavaScript-based technology stack for building modern web applications. It includes MongoDB, Express.js, Angular, and Node.js—together forming a powerful full-stack development environment. Whether you're a beginner or switching from another stack, setting up the MEAN stack is straightforward if you follow the right steps. Here’s a complete guide to get you started.
1. Install Node.js and npm
Node.js is the runtime that allows you to run JavaScript on the server side. npm (Node Package Manager) comes bundled with Node.js and is used to install project dependencies.
Visit https://nodejs.org
Download the latest LTS version for your OS
Install and verify:
bash
Copy
Edit
node -v
npm -v
2. Install MongoDB
MongoDB is the NoSQL database used in the MEAN stack. You can either install it locally or use a cloud-based service like MongoDB Atlas.
Visit https://www.mongodb.com/try/download/community
Follow the installer steps
Start MongoDB service:
bash
Copy
Edit
mongod
For cloud:
Go to https://www.mongodb.com/cloud/atlas
Create a free cluster and get your connection URI.
3. Install Angular CLI
Angular is the frontend framework in the MEAN stack. Use the Angular CLI to quickly scaffold and manage Angular applications.
Install globally:
bash
Copy
Edit
npm install -g @angular/cli
Verify:
bash
Copy
Edit
ng version
Create a new Angular project:
bash
Copy
Edit
ng new frontend
cd frontend
ng serve
4. Set Up Express and Node.js Backend
Create a folder for your backend application:
bash
Copy
Edit
mkdir backend
cd backend
npm init -y
npm install express mongoose cors
Create a basic Express server (index.js):
javascript
Copy
Edit
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const cors = require('cors');
app.use(cors());
app.use(express.json());
app.get('/', (req, res) => {
res.send('Hello from backend!');
});
app.listen(5000, () => console.log('Server running on port 5000'));
Run the backend server:
bash
Copy
Edit
node index.js
5. Connect Frontend and Backend
To connect Angular with Express:
Use Angular’s HttpClient to make API requests to http://localhost:5000/
Enable CORS in your backend to allow cross-origin requests
Final Thoughts
Setting up the MEAN stack environment prepares you for full-stack development with JavaScript across both frontend and backend. With your tools in place, you can now begin building dynamic, scalable web applications with ease.
Learn MEAN Stack Training Course
Read more:
Why Choose MEAN Stack for Web Development?
Visit Quality Thought Training Institute
Get Direction
Comments
Post a Comment