openSUSE

How To Install MEAN Stack on openSUSE

Install MEAN Stack on openSUSE

The MEAN stack represents one of the most powerful and versatile JavaScript-based frameworks available for modern web development. This comprehensive technology bundle combines four key components: MongoDB (a flexible NoSQL database), Express.js (a minimal and flexible Node.js web application framework), Angular (a platform for building mobile and desktop web applications), and Node.js (a JavaScript runtime environment). Together, these technologies create a robust foundation for developing dynamic, responsive, and scalable web applications.

What makes the MEAN stack particularly attractive is its use of JavaScript throughout the entire development process, from client to server to database. This unified language approach significantly streamlines development workflows and reduces the cognitive load on developers who no longer need to switch between different programming languages. The MEAN stack is especially well-suited for real-time applications, cloud-native environments, and single-page applications that require dynamic content loading.

In this comprehensive guide, we’ll walk through the complete process of installing and configuring the MEAN stack on openSUSE, a powerful and flexible Linux distribution. By the end of this tutorial, you’ll have a fully functional MEAN development environment ready for building modern web applications.

Table of Contents

Prerequisites

Before diving into the installation process, ensure your system meets the following requirements:

System Requirements

To successfully install and run the MEAN stack on openSUSE, your system should meet these minimum specifications:

  • A server or desktop running openSUSE (latest stable version recommended)
  • At least 2GB RAM (4GB or more recommended for development)
  • Minimum 10GB of free disk space
  • Internet connection for downloading packages
  • Basic knowledge of Linux command line operations

User Privileges

You’ll need administrative access to install packages and configure services:

  • A user account with sudo privileges or root access
  • Ability to execute system commands and modify configuration files

Knowledge Requirements

While this guide aims to be comprehensive, having some foundational knowledge will be beneficial:

  • Basic Linux command line familiarity
  • Understanding of package management in openSUSE (zypper)
  • Fundamental web development concepts
  • Basic understanding of JavaScript programming

Network Configuration

For a complete development or production environment, consider:

  • Properly configured network settings on your openSUSE system
  • Firewall rules that allow necessary ports (27017 for MongoDB, 3000 for Express, 4200 for Angular development server)
  • Domain name configuration (optional, but recommended for production environments)

With these prerequisites in place, you’re ready to begin preparing your openSUSE environment for the MEAN stack installation.

Preparing Your openSUSE Environment

Before installing the MEAN stack components, it’s essential to prepare your openSUSE system for optimal performance and compatibility. This preparation ensures all dependencies are available and the system is up-to-date.

System Update and Upgrade

Start by updating your openSUSE system to ensure you have the latest packages and security updates:

sudo zypper ref
sudo zypper update

These commands refresh your repository information and update all packages to their latest versions. It’s crucial to start with an updated system to avoid compatibility issues during installation.

Installing Essential Development Tools

Next, install the development tools and libraries required for building and running MEAN stack applications:

sudo zypper install -y git make gcc gcc-c++ libtool

These packages provide the essential build tools needed for compiling and installing certain Node.js modules and dependencies.

Setting Up External Repositories

Some MEAN stack components might require repositories not included in the default openSUSE repositories. Add them as follows:

sudo zypper addrepo https://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_Leap_15.3/devel:languages:nodejs.repo
sudo zypper refresh

Adjust the URL according to your specific openSUSE version if needed.

Terminal Configuration

To enhance your development workflow, consider setting up some helpful aliases in your bash profile:

echo "alias npmlist='npm list -g --depth=0'" >> ~/.bashrc
echo "alias ng='npx @angular/cli'" >> ~/.bashrc
source ~/.bashrc

These aliases will make working with npm packages and Angular CLI more convenient.

Firewall Configuration

Configure the firewall to allow traffic on the ports used by MEAN stack components:

sudo firewall-cmd --permanent --add-port=27017/tcp  # MongoDB
sudo firewall-cmd --permanent --add-port=3000/tcp   # Express.js app
sudo firewall-cmd --permanent --add-port=4200/tcp   # Angular development server
sudo firewall-cmd --reload

This ensures that your development environment isn’t blocked by firewall restrictions.

With your openSUSE environment properly prepared, you’re now ready to install the individual components of the MEAN stack, starting with Node.js and npm.

Installing Node.js and npm

Node.js and npm (Node Package Manager) form the foundation of the MEAN stack, providing the JavaScript runtime environment and package management capabilities essential for modern web development.

Adding the Node.js Repository

First, we’ll add the official Node.js repository to ensure we get the latest stable version:

sudo zypper addrepo https://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_Leap_15.3/devel:languages:nodejs.repo
sudo zypper refresh

This adds the Node.js repository specific to openSUSE and refreshes the package lists.

Installing Node.js

Now, install Node.js and npm using zypper, openSUSE’s package manager:

sudo zypper install nodejs npm

This will install both Node.js and npm on your system. The installation process may take a few minutes depending on your internet connection and system performance.

Verifying the Installation

After installation, verify that both Node.js and npm are installed correctly by checking their versions:

node -v
npm -v

These commands should display the version numbers of the installed Node.js and npm. If you see version numbers, the installation was successful.

Configuring npm

Configure npm to install global packages without requiring root privileges:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

This configuration allows you to install global npm packages without using sudo, which is a safer approach.

Installing Node Version Manager (Optional)

For developers who need to work with multiple Node.js versions, Node Version Manager (nvm) provides a flexible solution:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc

With nvm installed, you can easily switch between different Node.js versions:

nvm install --lts  # Install the latest LTS version
nvm use 16         # Switch to version 16

This optional step allows greater flexibility in managing Node.js versions for different projects.

Troubleshooting Node.js Installation

If you encounter any issues during the Node.js installation, try these solutions:

  • Permission errors: Use the npm configuration provided above or temporarily use sudo for global installations
  • Package conflicts: Remove any previous installations with sudo zypper remove nodejs npm before reinstalling
  • Version conflicts: Use nvm to manage multiple Node.js versions
  • Repository errors: Verify the repository URL is correct for your openSUSE version

With Node.js and npm successfully installed, you’ve established the runtime environment necessary for the MEAN stack. Next, we’ll install MongoDB, the database component of the stack.

Installing MongoDB

MongoDB is a flexible, document-oriented NoSQL database that stores data in JSON-like documents. Its schema-less design makes it ideal for agile development and storing complex data structures. Let’s install and configure MongoDB on your openSUSE system.

Adding the MongoDB Repository

First, you need to add the MongoDB repository to your system. Create a new repository file:

sudo zypper addrepo --gpgcheck-allow-unsigned https://repo.mongodb.org/zypper/opensuse/15/mongodb-org/5.0/x86_64/ mongodb
sudo zypper refresh

This adds the official MongoDB repository to your system’s package sources.

Installing MongoDB

Now, install MongoDB using zypper:

sudo zypper install mongodb-org

This command installs the complete MongoDB package including the server, shell, and tools.

Configuring MongoDB Service

After installation, enable and start the MongoDB service to ensure it runs automatically at system startup:

sudo systemctl enable mongod
sudo systemctl start mongod

Verify that the service is running correctly:

sudo systemctl status mongod

You should see an “active (running)” status, indicating that MongoDB has started successfully.

Configuring MongoDB Security

By default, MongoDB accepts connections only from localhost. For a more secure setup, configure authentication:

# Connect to MongoDB shell
mongosh

# Switch to admin database
use admin

# Create admin user
db.createUser({
  user: "adminUser",
  pwd: "securePassword",
  roles: [{ role: "userAdminAnyDatabase", db: "admin" }]
})

# Exit the shell
exit

Then, edit the MongoDB configuration file to enable authentication:

sudo nano /etc/mongod.conf

Add or modify the security section:

security:
  authorization: enabled

Save the file and restart MongoDB:

sudo systemctl restart mongod

This configuration adds basic authentication to your MongoDB installation.

Testing MongoDB Connection

Verify that MongoDB is working correctly by connecting to it:

mongosh --host localhost:27017

If MongoDB is running properly, you’ll see the MongoDB shell prompt. For an authenticated connection:

mongosh --host localhost:27017 -u adminUser -p securePassword --authenticationDatabase admin

Try creating a test database to ensure everything is functioning:

use testdb
db.test.insertOne({ name: "test item", value: 123 })
db.test.find()

These commands should create a new document and retrieve it from the database.

Troubleshooting MongoDB Installation

If you encounter issues with MongoDB:

  • Service fails to start: Check the logs with sudo journalctl -u mongod
  • Permission issues: Ensure proper ownership of data directories with sudo chown -R mongod:mongod /var/lib/mongodb
  • Connection refused: Verify that MongoDB is listening on the expected port with sudo netstat -plntu | grep mongo
  • Storage issues: Make sure you have enough disk space and proper permissions on the data directory

With MongoDB successfully installed and configured, you’ve completed the database component of the MEAN stack. Next, we’ll install Express.js, the web application framework.

Installing Express.js

Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. It simplifies the process of creating server-side applications and APIs. Let’s install and configure Express.js on your openSUSE system.

Understanding Express.js

Express.js serves as a backend framework that handles HTTP requests, routes, middleware, and responses. It’s designed to be lightweight and unobtrusive, allowing developers to build web applications with minimal overhead.

Installing Express.js Globally

While Express.js is typically installed locally in each project, you might want to install it globally for convenience:

npm install -g express

This command installs Express.js globally, making it available system-wide.

Installing Express Generator

Express Generator is a tool that creates an Express application skeleton, saving you time in setting up project structures:

npm install -g express-generator

This utility will help you quickly generate Express.js application templates with various configurations.

Creating a Basic Express.js Application

With Express Generator installed, create a basic Express.js application:

express myapp --view=ejs
cd myapp
npm install

These commands create a new Express.js application with the EJS view engine, navigate to the project directory, and install all dependencies.

Understanding the Express.js Project Structure

The generated project structure includes several important directories:

  • bin/: Contains the application startup script
  • public/: Stores static assets like CSS, JavaScript, and images
  • routes/: Contains route definitions
  • views/: Stores view templates
  • app.js: The main application file

Familiarize yourself with this structure as it forms the foundation of your Express.js applications.

Configuring Express.js

Edit the app.js file to customize your Express.js application:

nano app.js

You might want to add additional middleware, configure CORS, or set up database connections here:

// Example of adding MongoDB connection
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/myapp', {
  useNewUrlParser: true,
  useUnifiedTopology: true
})
.then(() => console.log('MongoDB connected'))
.catch(err => console.error('MongoDB connection error:', err));

Save the file after making your changes.

Running Your Express.js Application

Start your Express.js application:

npm start

By default, the application will run on port 3000. Open a web browser and navigate to http://localhost:3000 to see your Express.js application in action.

Troubleshooting Express.js Installation

If you encounter issues with Express.js:

  • Dependency errors: Update npm with npm update -g npm and try reinstalling
  • Permission errors: Use the npm configuration from the Node.js section or temporarily use sudo
  • Port conflicts: Change the default port in bin/www if port 3000 is already in use
  • Connection issues: Verify network configurations and firewall settings

With Express.js installed and configured, you’ve completed another major component of the MEAN stack. Next, we’ll install Angular, the frontend framework that completes the stack.

Installing Angular CLI

Angular is a powerful platform for building web applications, providing a comprehensive solution for frontend development. Angular CLI (Command Line Interface) simplifies the development process by providing tools for project scaffolding, development, and deployment. Let’s install and set up Angular CLI on your openSUSE system.

Understanding Angular

Angular is a platform and framework for building single-page client applications using HTML and TypeScript. It implements core and optional functionality as a set of TypeScript libraries that you import into your applications.

Installing Angular CLI

Angular CLI is a command-line interface tool for initializing, developing, scaffolding, and maintaining Angular applications. Install it globally using npm:

npm install -g @angular/cli

This command installs the latest version of Angular CLI globally on your system.

Verifying the Installation

After installation, verify that Angular CLI is installed correctly:

ng version

This command displays information about the installed Angular CLI version, Angular core libraries, and related dependencies.

Creating Your First Angular Application

With Angular CLI installed, create your first Angular application:

ng new my-angular-app

This command prompts you with questions about features to include in your application. You can customize the following options:

  • Whether to include Angular routing (typically yes)
  • Which stylesheet format to use (CSS, SCSS, SASS, LESS, or Stylus)

After answering these questions, Angular CLI will create a new project with the specified configuration.

Understanding the Angular Project Structure

Navigate to your newly created project directory:

cd my-angular-app

The Angular project structure includes:

  • src/app/: Contains the components, services, and modules
  • src/assets/: Stores static files like images
  • src/environments/: Contains environment-specific configuration
  • angular.json: Angular workspace configuration
  • package.json: Project dependencies and scripts

Take some time to explore this structure as it forms the foundation of your Angular applications.

Running Your Angular Application

Start the development server:

ng serve --open

This command compiles the application and starts a development server on port 4200. The --open flag automatically opens the application in your default web browser.

Building for Production

When you’re ready to deploy your application, build it for production:

ng build --prod

This command creates optimized production files in the dist/ directory, which you can deploy to a web server.

Troubleshooting Angular CLI Installation

If you encounter issues with Angular CLI:

  • Node.js version incompatibility: Angular requires a specific Node.js version range. Check the requirements and update if necessary
  • Permission errors: Use the npm configuration from the Node.js section or temporarily use sudo
  • Memory issues: Increase Node.js memory limit with NODE_OPTIONS=--max_old_space_size=4096 ng build
  • Port conflicts: Change the default port with ng serve --port 4201 if port 4200 is already in use

With Angular CLI successfully installed, you’ve completed all the individual components of the MEAN stack. Next, we’ll create a basic MEAN stack application that integrates all these components.

Creating a Basic MEAN Stack Application

Now that you have all the components of the MEAN stack installed on your openSUSE system, it’s time to create a basic application that integrates MongoDB, Express.js, Angular, and Node.js. This section will guide you through setting up a complete MEAN stack project from scratch.

Project Directory Setup

First, create a directory for your MEAN stack project:

mkdir mean-project
cd mean-project

Initialize a new Node.js project:

npm init -y

This creates a package.json file with default values.

Setting Up the Backend

Create the server directory structure:

mkdir -p server/routes server/models server/controllers
touch server/server.js

Install the necessary dependencies:

npm install express mongoose cors body-parser

These packages provide the core functionality for your Express.js backend and MongoDB connectivity.

Creating the Express.js Server

Edit the server.js file:

nano server/server.js

Add the following code:

const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const path = require('path');

// Initialize Express app
const app = express();
const PORT = process.env.PORT || 3000;

// Middleware
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

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

// Define routes
app.get('/api', (req, res) => {
  res.json({ message: 'Welcome to the MEAN Stack API' });
});

// Serve static files in production
if (process.env.NODE_ENV === 'production') {
  app.use(express.static(path.join(__dirname, '../client/dist/client')));
  app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, '../client/dist/client/index.html'));
  });
}

// Start server
app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

This code sets up a basic Express.js server with MongoDB connection and API endpoints.

Creating a MongoDB Model

Create a simple model:

nano server/models/item.js

Add the following code:

const mongoose = require('mongoose');

const ItemSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true
  },
  description: {
    type: String,
    required: true
  },
  createdAt: {
    type: Date,
    default: Date.now
  }
});

module.exports = mongoose.model('Item', ItemSchema);

This defines a simple MongoDB schema for storing items.

Creating the Angular Frontend

Now, create the Angular application in the client directory:

ng new client --skip-git --directory=client
cd client

Generate a component to display and interact with the data:

ng generate component items

Update the items component to interact with the backend API:

nano src/app/items/items.component.ts

Add the following code:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-items',
  templateUrl: './items.component.html',
  styleUrls: ['./items.component.css']
})
export class ItemsComponent implements OnInit {
  items = [];
  newItem = { name: '', description: '' };
  apiUrl = 'http://localhost:3000/api/items';

  constructor(private http: HttpClient) { }

  ngOnInit(): void {
    this.fetchItems();
  }

  fetchItems(): void {
    this.http.get(this.apiUrl).subscribe(
      (data: any) => {
        this.items = data;
      },
      error => console.error('Error fetching items:', error)
    );
  }

  addItem(): void {
    this.http.post(this.apiUrl, this.newItem).subscribe(
      response => {
        this.fetchItems();
        this.newItem = { name: '', description: '' };
      },
      error => console.error('Error adding item:', error)
    );
  }
}

Configure the HttpClientModule in app.module.ts:

nano src/app/app.module.ts

Update the file:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { ItemsComponent } from './items/items.component';

@NgModule({
  declarations: [
    AppComponent,
    ItemsComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

This sets up the necessary imports for HTTP communication with the backend.

Running the Full Stack Application

Open two terminal windows. In the first, start the Express.js server:

cd mean-project
node server/server.js

In the second terminal, start the Angular development server:

cd mean-project/client
ng serve --open

You now have a basic MEAN stack application running with a MongoDB database, Express.js server, Angular frontend, and Node.js runtime environment.

Testing the Application

Open your browser and navigate to http://localhost:4200 to see your Angular application. The application should communicate with your Express.js backend, which in turn interacts with MongoDB to store and retrieve data.

This completes the basic setup of a MEAN stack application on openSUSE. In the next section, we’ll discuss how to prepare this application for production deployment.

Configuring for Production Deployment

Once your MEAN stack application is developed and tested, it’s time to prepare it for production deployment. This section covers the necessary steps to ensure your application is secure, optimized, and reliably hosted on your openSUSE server.

Setting Up Nginx as a Reverse Proxy

Nginx is a high-performance web server that can serve as a reverse proxy for your MEAN stack application:

sudo zypper install nginx

Create a configuration file for your application:

sudo nano /etc/nginx/conf.d/mean-app.conf

Add the following configuration:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Enable and start Nginx:

sudo systemctl enable nginx
sudo systemctl start nginx

This configuration routes all traffic from port 80 to your Express.js server running on port 3000.

Process Management with PM2

PM2 is a process manager for Node.js applications that helps keep your application running in production:

npm install -g pm2

Create an ecosystem file for your application:

cd mean-project
pm2 ecosystem

Edit the ecosystem.config.js file:

nano ecosystem.config.js

Configure your application:

module.exports = {
  apps: [{
    name: "mean-app",
    script: "./server/server.js",
    instances: "max",
    exec_mode: "cluster",
    env: {
      NODE_ENV: "development",
    },
    env_production: {
      NODE_ENV: "production",
    }
  }]
}

Start your application with PM2:

pm2 start ecosystem.config.js --env production

Configure PM2 to start automatically on system boot:

pm2 startup
pm2 save

This ensures your application stays running even after system reboots.

Setting Up SSL/TLS with Let’s Encrypt

Secure your application with SSL/TLS using Let’s Encrypt:

sudo zypper install certbot python-certbot-nginx

Obtain and install a certificate:

sudo certbot --nginx -d your-domain.com

Follow the prompts to complete the certificate installation. Certbot will automatically update your Nginx configuration to use HTTPS.

Environment Variables for Production

Create a .env file for production environment variables:

nano server/.env

Add your production settings:

NODE_ENV=production
PORT=3000
MONGODB_URI=mongodb://localhost:27017/meanDB
JWT_SECRET=your_secure_jwt_secret

Update your server.js to use these environment variables:

npm install dotenv

And at the top of server.js:

require('dotenv').config();

This helps keep sensitive information out of your code repository.

Database Backup Strategy

Set up regular MongoDB backups:

mkdir -p /backup/mongodb

Create a backup script:

nano /backup/mongo-backup.sh

Add the following content:

#!/bin/bash
DATE=$(date +%Y-%m-%d)
BACKUP_DIR="/backup/mongodb"
mongodump --out $BACKUP_DIR/$DATE
find $BACKUP_DIR -type d -mtime +7 -exec rm -rf {} \;

Make the script executable and schedule it with cron:

chmod +x /backup/mongo-backup.sh
crontab -e

Add a daily backup job:

0 2 * * * /backup/mongo-backup.sh

This creates daily backups and retains them for one week.

Monitoring and Logging

Install and configure monitoring for your application:

pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 10M
pm2 set pm2-logrotate:retain 7

For more comprehensive monitoring, consider using PM2 Plus or other monitoring solutions like Prometheus and Grafana.

With these configurations in place, your MEAN stack application is ready for production use. The next section will cover troubleshooting common issues you might encounter during development or production.

Troubleshooting Common Issues

When working with the MEAN stack on openSUSE, you may encounter various issues that can disrupt your development workflow or affect your production application. This section addresses common problems and provides solutions to help you overcome these challenges.

MongoDB Connection Issues

Problem: Unable to connect to MongoDB.

Solutions:

  • Verify that the MongoDB service is running: sudo systemctl status mongod
  • Check MongoDB logs for errors: sudo journalctl -u mongod
  • Ensure the correct connection string is used in your application
  • Verify network connectivity and firewall settings
  • Check authentication credentials if authentication is enabled

Example fix:

# Restart MongoDB service
sudo systemctl restart mongod

# Check MongoDB status
sudo systemctl status mongod

# Verify connection manually
mongosh --host localhost:27017

Node.js and npm Version Conflicts

Problem: Package compatibility issues due to Node.js or npm versions.

Solutions:

  • Use nvm to install and switch to the required Node.js version
  • Update npm to the latest version: npm install -g npm@latest
  • Check package.json for specific version requirements
  • Delete node_modules directory and package-lock.json, then reinstall dependencies

Example fix:

# Install and use specific Node.js version
nvm install 16
nvm use 16

# Clear npm cache and reinstall dependencies
npm cache clean --force
rm -rf node_modules package-lock.json
npm install

Express.js Server Issues

Problem: Express.js server won’t start or crashes unexpectedly.

Solutions:

  • Check for port conflicts (another process might be using the same port)
  • Verify file paths in your Express.js configuration
  • Look for syntax errors in your server code
  • Check for unhandled promise rejections or exceptions

Example fix:

# Find process using port 3000
sudo lsof -i :3000

# Kill the process if needed
sudo kill -9 

# Start server with debugging
NODE_DEBUG=* node server.js

Angular Build Problems

Problem: Angular application fails to build or compile.

Solutions:

  • Check for TypeScript errors in your components
  • Verify that dependencies are correctly installed
  • Increase Node.js memory limit for large applications
  • Check Angular version compatibility with your dependencies

Example fix:

# Increase Node.js memory limit
export NODE_OPTIONS=--max_old_space_size=4096

# Run Angular with verbose logging
ng build --verbose

# Update Angular dependencies
ng update @angular/cli @angular/core

Cross-Origin Resource Sharing (CORS) Issues

Problem: Browser blocks requests due to CORS policy.

Solutions:

  • Configure CORS properly in your Express.js server
  • Verify that the correct headers are being set
  • Use a CORS middleware in Express.js

Example fix:

// Add to server.js
const cors = require('cors');
app.use(cors({
  origin: 'http://localhost:4200',
  methods: ['GET', 'POST', 'PUT', 'DELETE'],
  allowedHeaders: ['Content-Type', 'Authorization']
}));

Production Deployment Issues

Problem: Application works locally but fails in production.

Solutions:

  • Check environment variables and configuration differences
  • Verify that build processes completed successfully
  • Check server logs for errors
  • Ensure proper permissions for files and directories
  • Verify that all services are running correctly

Example fix:

# Check application logs
pm2 logs mean-app

# Verify service status
sudo systemctl status nginx
sudo systemctl status mongod

# Check file permissions
sudo chown -R yourusername:yourusername /path/to/application

Memory Leaks and Performance Issues

Problem: Application becomes slower over time or uses excessive memory.

Solutions:

  • Use monitoring tools like PM2 to track resource usage
  • Look for memory leaks using Node.js profiling tools
  • Optimize database queries and indexing
  • Implement proper connection pooling and resource cleanup

Example fix:

# Monitor memory usage with PM2
pm2 monit

# Create database indexes for frequently queried fields
mongosh
use meanDB
db.items.createIndex({ name: 1 })

By addressing these common issues proactively, you can maintain a stable and efficient MEAN stack application on your openSUSE system. Remember that detailed logs are your best friend when troubleshooting complex applications.

Congratulations! You have successfully installed MEAN Stack. Thanks for using this tutorial for installing MEAN Stack on openSUSE Linux system. For additional help or useful information, we recommend you check the official Manjaro website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button