Logo

How to Host a Node.js Website on Plesk

How to Host a Node.js Website on Plesk

This guide explains how to upload, configure, and run Node.js applications on a Plesk server. Node.js is an open-source runtime environment that allows you to run JavaScript code outside a web browser, making it perfect for building fast, scalable web applications.

How to Host a Node.js Website on Plesk

What You'll Need

Before starting, make sure you have:

  • A Plesk server with the Node.js Toolkit extension installed
  • Your Node.js application ready to upload
  • FTP/SFTP credentials or File Manager access
  • Basic knowledge of your application's structure

Note: This guide assumes your hosting provider has already installed the Node.js Toolkit extension. If the Node.js option doesn't appear in your Plesk panel, contact your hosting provider.

Understanding Node.js Application Structure

Before uploading your application, it's important to understand its directory structure:

Application Root

The main directory containing all your application files and subdirectories. This is where you'll find:

  • package.json - Lists dependencies and scripts
  • node_modules/ - Installed packages (don't upload this folder)
  • Application code files
  • Configuration files

Document Root

A subdirectory within the application root that contains static files like:

  • HTML files
  • CSS stylesheets
  • JavaScript files for the browser
  • Images and other assets
  • Often called public/, static/, or dist/

Application Startup File

The main file that starts your application. Common names:

  • app.js
  • server.js
  • index.js
  • main.js

Example structure:

my-nodejs-app/              ← Application Root
├── package.json
├── app.js                  ← Startup File
├── node_modules/
├── public/                 ← Document Root
│   ├── index.html
│   ├── css/
│   └── js/
├── routes/
└── views/

Step 1: Upload Your Application

You have several options to upload your Node.js application to Plesk.

Option A: Using Plesk File Manager (Easiest)

  1. Log in to Plesk
  2. Go to Websites & Domains
  3. Find your domain and click Files (File Manager icon)
  4. Navigate to your domain's directory (usually /httpdocs or /)
  5. Create a new folder for your application or use the existing directory
  6. Click Upload and select your application files
  7. If you have a .zip or .tar.gz file, upload it and extract it

Important: Do NOT upload the node_modules folder - Plesk will install dependencies automatically later.

Option B: Using FTP/SFTP Client

  1. Open your FTP client (FileZilla, WinSCP, etc.)
  2. Connect using your FTP credentials:
    • Host: Your domain or server IP
    • Username: Your FTP username
    • Password: Your FTP password
    • Port: 21 (FTP) or 22 (SFTP)
  3. Navigate to your domain directory
  4. Upload all application files except node_modules/
  5. Preserve the directory structure

If your application is in a Git repository:

  1. Go to Websites & Domains
  2. Click Git (requires Git extension)
  3. Click Clone Repository
  4. Enter your repository URL
  5. Select the destination directory
  6. Click OK

Plesk will clone your repository automatically.

Step 2: Configure Your Node.js Application

Once your files are uploaded, configure the application to run properly.

Access Node.js Configuration

  1. Log in to Plesk
  2. Go to Websites & Domains
  3. Find your domain
  4. Click Create Website > Node.js

Or if already created:

  • Click the Node.js button on your domain card

Configure Application Settings

You'll see a configuration screen with several options:

1. Node.js Version

What it is: The version of Node.js runtime that will run your application.

How to choose:

  • Check your application's package.json file for the required Node.js version
  • Look for an "engines" section:
    "engines": {
      "node": ">=18.0.0"
    }
    
  • If unsure, select the latest LTS (Long Term Support) version
  • Common versions: 18.x, 20.x, 22.x

Example: Select Node.js 20.x for modern applications.

2. Package Manager

What it is: The tool used to install your application's dependencies.

Options:

  • npm - Default Node.js package manager (most common)
  • Yarn - Alternative package manager (faster, more reliable)

How to choose:

  • If your project has yarn.lock file → Choose Yarn
  • If your project has package-lock.json file → Choose npm
  • Plesk usually detects this automatically

Example: Most applications use npm, so that's the safe choice.

3. Document Root

What it is: The directory containing static files (HTML, CSS, images).

How to configure:

  • Click the folder icon
  • Navigate to your static files directory
  • Common names: public/, static/, dist/, build/

Examples:

  • Express app with static folder: /httpdocs/my-app/public
  • React app: /httpdocs/my-app/build
  • Simple app: /httpdocs/my-app (if no separate static folder)

4. Application Mode

What it is: Sets the NODE_ENV environment variable.

Options:

  • Development - For testing (verbose errors, hot reload)
  • Production - For live sites (optimized, minimal logging)
  • Custom - Enter your own value

How to choose:

  • Use Development while testing
  • Switch to Production when going live

Example: Start with Development, change to Production later.

5. Application Root

What it is: The main directory containing all your application files.

How to configure:

  • Click the folder icon
  • Select the directory where you uploaded your application
  • This should contain package.json and your startup file

Example: /httpdocs/my-nodejs-app

6. Application Startup File

What it is: The JavaScript file that starts your application.

How to configure:

  • Enter the filename (not the full path)
  • Common names: app.js, server.js, index.js, main.js
  • Check your package.json file's "main" field for the correct file

Example in package.json:

{
  "main": "server.js"
}

Then enter: server.js

7. Custom Environment Variables (Optional)

What it is: Additional configuration variables your application might need.

Common examples:

  • PORT - Server port (usually set by Plesk automatically)
  • DATABASE_URL - Database connection string
  • API_KEY - Third-party service keys
  • SECRET_KEY - Application secret for sessions

How to add:

  1. Click Add Variable
  2. Enter Variable Name (e.g., API_KEY)
  3. Enter Variable Value (e.g., your-api-key-here)
  4. Click OK

Example:

DATABASE_URL = mongodb://localhost:27017/myapp
API_KEY = sk_test_123456789

Save Configuration

After filling in all settings, click OK to save your configuration.

Step 3: Install Dependencies and Start Application

Now that your application is configured, it's time to install dependencies and start it.

Access Node.js Control Panel

  1. Go to Websites & Domains
  2. Find your domain
  3. Click the Node.js button

Enable Node.js

  1. Click Enable Node.js
    • This activates the Node.js runtime for your application

Install Dependencies

  1. Click NPM Install (or Yarn Install if using Yarn)
    • This installs all packages listed in package.json
    • This step is required and only needs to be done once
    • Wait for the installation to complete (may take 1-5 minutes)
    • You'll see a success message when done

What happens:

  • Plesk reads your package.json file
  • Downloads and installs all dependencies
  • Creates the node_modules folder
  • Similar to running npm install on command line

Run Build Scripts (If Required)

Some applications need build scripts to run before starting:

  1. Click Run Script (optional)
    • Enter the script name from your package.json
    • Common scripts: build, setup, migrate
    • Click OK

Example package.json scripts:

{
  "scripts": {
    "start": "node app.js",
    "build": "webpack --mode production"
  }
}

To run the build script, enter: build

Verify Application is Running

After installation and starting:

  • The Node.js version should appear under the Node.js button on your domain card
  • Your application is now live and accessible

Step 4: Access Your Website

Your Node.js application should now be running!

Test Your Application

Open your web browser and go to:

http://your-domain.com

or

https://your-domain.com

You should see your Node.js application running.

Common Access Patterns

Depending on your application setup:

Root access:

  • http://yourdomain.com/ - Main application

API endpoints:

  • http://yourdomain.com/api/users - API routes

Static files:

  • http://yourdomain.com/css/style.css - Static assets

Managing Your Application

Stop Your Application

To stop your Node.js application:

  1. Go to Websites & Domains
  2. Click Node.js
  3. Click Disable Node.js

Note: This doesn't delete your files or settings. You can restart anytime.

Restart Your Application

After making code changes:

  1. Click Node.js
  2. Click Restart App (or Disable then Enable)

Important: You must restart the application for code changes to take effect!

Update Dependencies

When you modify package.json:

  1. Click Node.js
  2. Click NPM Install (or Yarn Install)
  3. Wait for installation to complete
  4. Click Restart App

View Application Logs

To troubleshoot issues or monitor your application:

  1. Go to Websites & Domains
  2. Click Logs
  3. Look for entries with Node.js tag
  4. Use the filter to show only Node.js logs

What you'll see:

  • Application console output
  • Error messages
  • console.log() statements
  • Crash reports

Common Configuration Examples

Express.js Application

Typical setup:

  • Node.js Version: 18.x or 20.x
  • Package Manager: npm
  • Application Root: /httpdocs/my-express-app
  • Document Root: /httpdocs/my-express-app/public
  • Startup File: app.js or server.js
  • Application Mode: Development (testing) → Production (live)

React/Next.js Application

Typical setup:

  • Node.js Version: 18.x or 20.x
  • Package Manager: npm or Yarn
  • Application Root: /httpdocs/my-react-app
  • Document Root: /httpdocs/my-react-app/build (React) or /httpdocs/my-react-app/out (Next.js)
  • Startup File: Usually handled by framework
  • Application Mode: Production
  • Build Script: Run build before starting

API Server (No Static Files)

Typical setup:

  • Node.js Version: Latest LTS
  • Package Manager: npm
  • Application Root: /httpdocs/my-api
  • Document Root: Same as Application Root
  • Startup File: index.js or server.js
  • Application Mode: Production
  • Environment Variables: Database URL, API keys

Troubleshooting

Application Won't Start

Check the following:

  1. Correct startup file:
    • Verify the filename is correct
    • Check package.json "main" field
  2. Dependencies installed:
    • Run NPM Install again
    • Check logs for installation errors
  3. Node.js version:
    • Ensure version matches your app requirements
    • Try a different version if needed
  4. View logs:
    • Go to Logs to see error messages
    • Look for missing modules or syntax errors

Cannot Access Website

Possible causes:

  1. Application not enabled:
    • Click Enable Node.js
  2. Wrong document root:
    • Verify static files are in correct directory
    • Check document root path in settings
  3. Port conflicts:
    • Plesk manages ports automatically
    • Don't hardcode ports in your code
  4. File permissions:
    • Ensure files are readable
    • Check folder permissions

Errors After Code Changes

Solution:

  1. Click Node.js
  2. Click Restart App
  3. Node.js applications don't auto-reload by default

Module Not Found Errors

Solution:

  1. Check package.json has all dependencies listed
  2. Run NPM Install again
  3. Restart the application

Application Crashes

Steps to diagnose:

  1. View Logs for error messages
  2. Check code for syntax errors
  3. Verify environment variables are set correctly
  4. Test locally before deploying

Best Practices

Security

  1. Use Production mode for live sites
  2. Don't commit sensitive data to Git
  3. Use environment variables for secrets
  4. Keep dependencies updated

Performance

  1. Enable Production mode for optimization
  2. Use latest Node.js LTS version
  3. Minimize dependencies
  4. Use caching where appropriate

Maintenance

  1. Check logs regularly
  2. Update dependencies periodically
  3. Backup your code before changes
  4. Test locally before deploying

Summary

To host a Node.js application on Plesk:

  1. Upload your application files (without node_modules)
  2. Configure in Plesk:
    • Set Node.js version
    • Choose package manager
    • Set application root and document root
    • Specify startup file
    • Add environment variables
  3. Install dependencies with NPM/Yarn Install
  4. Enable Node.js to start the application
  5. Access your website at your domain

Your Node.js application is now live on Plesk!

Join our Discord community server

For any questions, suggestions, or just to chat with the community, join us on Discord!

900+Members