Skip to content

Method for Installing MEAN Stack on Debian 12 Operating System

Guide on Installing the MEAN Stack (MongoDB, Express, Angular, Node.js) in Debian 12. Dive into this comprehensive guide to construct full-stack web applications.

Guide on Installing MEAN Stack on Debian 12 Operating System
Guide on Installing MEAN Stack on Debian 12 Operating System

Method for Installing MEAN Stack on Debian 12 Operating System

**Setting Up a MEAN Stack Development Environment on Debian 12**

Debian 12, known for its predictable behaviour and low maintenance, is a popular choice for cloud images, edge deployments, and academic hosting. This article will guide you through setting up a MEAN Stack development environment on Debian 12, allowing you to build full-stack JavaScript applications with Node.js and MongoDB backend and Angular frontend.

**Step 1: Update System and Install Essential Tools**

Begin by updating your package list and installing useful utilities:

```bash sudo apt update sudo apt upgrade -y sudo apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates ```

**Step 2: Install Node.js (v20 recommended)**

Add the NodeSource repository and install Node.js version 20:

```bash curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

sudo apt update sudo apt install -y nodejs ```

Verify installation:

```bash node -v npm -v ```

**Step 3: Install MongoDB**

Add the MongoDB official repository and install MongoDB:

```bash wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/debian $(lsb_release -sc)/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

sudo apt update sudo apt install -y mongodb-org ```

Start and enable MongoDB service:

```bash sudo systemctl start mongod sudo systemctl enable mongod sudo systemctl status mongod ```

**Step 4: Install Angular CLI**

The Angular CLI is installed globally through npm:

```bash sudo npm install -g @angular/cli ```

Verify Angular installation:

```bash ng version ```

**Step 5: Set Up Express.js in Your Project**

Create a new directory for your Express backend and initialize a Node.js project:

```bash mkdir mean-backend cd mean-backend npm init -y ```

Install Express.js and Mongoose (MongoDB ODM library for Node.js):

```bash npm install express mongoose ```

Create a basic Express server (`index.js`):

```javascript const express = require('express'); const mongoose = require('mongoose'); const app = express(); const port = 3000;

// Middleware to parse JSON app.use(express.json());

// Connect to MongoDB mongoose.connect('mongodb://localhost:27017/meanstackdb', { useNewUrlParser: true, useUnifiedTopology: true }) .then(() => console.log('MongoDB connected')) .catch(err => console.error(err));

// Example route app.get('/', (req, res) => { res.send('Express server is running'); });

app.listen(port, () => { console.log(`Server listening at http://localhost:${port}`); }); ```

Start the server:

```bash node index.js ```

**(Optional) Step 6: Create Angular Frontend**

Navigate to your projects folder and generate a new Angular project:

```bash ng new mean-frontend cd mean-frontend ng serve ```

This runs the Angular development server on `http://localhost:4200`.

**Summary Table for Debian 12 MEAN Setup**

| Component | Installation Command(s) | Notes | |-----------------|-------------------------------------------------------------------------------------------------------------|--------------------------------| | Node.js 20 | Add NodeSource repo + `sudo apt install -y nodejs` | Latest stable Node.js version | | MongoDB 6.0 | Add MongoDB repo + `sudo apt install -y mongodb-org` | Start and enable `mongod` service | | Angular CLI | `sudo npm install -g @angular/cli` | For frontend Angular projects | | Express & Mongoose | `npm install express mongoose` (within Node project) | Key backend libraries |

This provides you a complete development environment for MEAN stack on Debian 12, enabling you to build full-stack JavaScript applications with Node.js and MongoDB backend and Angular frontend. For production setup tips or environment variables configuration, these can be added later according to your deployment workflow.

[1] Adapted from Debian 12 instructions and Node.js setup [4] (Optional) Create Angular Frontend instructions adapted from Angular CLI documentation

Technology plays a crucial role in setting up a MEAN Stack development environment on Debian 12. Notably, you'll be working with Node.js (version 20 recommended) for the backend, MongoDB as the database, and Angular as the frontend. Each of these technologies is essential in building full-stack JavaScript applications, allowing you to leverage the power of technology to create your application efficiently.

Read also:

    Latest