How to Work with Node.js Apps on Plesk Obsidian

If you’re interested in hosting Node.js apps, we’ve got good news for you. Plesk comes with a Node.js extension that allows you to manage apps easily. In this article, we’ll describe in detail how to work with Node.js apps in the context of Plesk Obsidian, the latest version of Plesk.

Prerequisites

The first thing you need to do is install Plesk Obsidian. I chose Debian as the server OS for this article. You can use either a Linux distro or Windows – just note that there could be some minor differences if you go with a different OS. Assuming Plesk is already installed, let’s install the Node.js extension. 

Log in to Plesk, go to “Tools and Settings”, and click “Updates and Upgrades”. Next, go to “Add/Remove Components”. Find the “NodeJS support” component. Select it, and continue with the Node.JS installation. In a few minutes, all the necessary components will be installed and you’ll be ready to go!

Hosting a ‘Hello World’ App

To make sure everything works, let’s try to host a sample Node.js app, such as a “Hello, World” app. You can download one here. Copy/pasting the contents of the app.js file manually is an option. But I suggest trying out another Plesk extension instead – namely, the Git extension

First, you have to create a subscription (a domain with hosting). Then, you need to create a target directory where the app will be stored. Select your subscription, go to the “Files” tab, and create a directory named “hello-world”. Next, go to the “Domains” tab, choose the website, and click the “Git” button.

Local Repo Set Up

Now, you’ll learn how to set up a local repo as a mirror of a remote one, and deploy the code to the previously created directory. Set this URL as the remote Git repo URL, and change the target to the “hello-world” directory. The settings should look like this:

Differences Between ‘Document Root’ and ‘Application Root’

The next step is to change the “Document root” for the domain. Notice that I’ll be talking about  “Document root” and “Application root”: they aren’t one and the same. When we’re talking about web apps (e.g. Node.js based apps or similar), the “Document root” is the location where the static assets can be found. Meanwhile, the “Application root” is the root directory where the app itself is located. In most cases, the “Document root” is a directory inside the “Application root” directory (e.g. “public”). 

You need to change the document root now. To do so, go to “Domains”, select your website and go to “Hosting Settings”:

Change the existing document root to ‘hello-world/public’ (without quotes) and click the ‘Ok’ button to save the changes.

Enable Node.js Support

The last thing to do before you run the app is to enable Node.js support on the domain. Go to “Domains”, choose the website and click “Node.js”. Here you’ll see some information about your app and a row of buttons on top. Click “Enable Node.js”, and in a few seconds, your screen will look like this:

First, let’s click on the “Application URL” link to make sure that the app is running. If you see a “Hello, World!” message, congratulations! Your Node.js app is up and running.

App with Dependencies

Real-world Node.js apps always have external dependencies defined in the package.json file and installed in the node_modules directory. 

Let’s take a look at an Express-based app – you can download it from the repository here. Either repeat the steps above to set up a repository in Plesk, or download/upload the source code manually. Once you’re done, the Node.js settings screen should look like this – assuming you uploaded the code to the “express-demo” directory:

Installing Dependencies

Before you try accessing the app, you need to initialize it first. Let’s begin by installing dependencies – luckily, in Plesk, it’s as easy as clicking the “NPM install” button. This will install all app dependencies according to the package.json file. Then, you need to tune the app startup file. Plesk uses the Phusion Passenger application server to serve Node.js apps. Our demo app repository contains a file named “server.js”. This file is not a part of a typical Express-based app and contains just a few lines of code, but it’s nonetheless necessary for the app to run:

const app = require('./app');
const http = require('http');

http.createServer(app).listen(process.env.PORT);

You can use the idea behind this file when hosting other Node.js apps (e.g. based on a different framework). The last thing you need to do is to change the “Application Startup File” setting to “server.js”.

Now, try browsing the domain on which you installed the app – you should see the Express welcome message.

By default, the app is running in the “production” mode. If you modify the app, don’t forget to restart it by clicking the “Restart” button.

Knowing how to debug Node.js apps in case any issues appear is essential for a Node.js developer. Here are a few tips that can save you a lot of grief: 

Log Files Checkup

The first thing to do when troubleshooting a Node.js app is to check the log files. For example, if you forget to install the dependencies for the demo Express app (you do it via the “NPM install” button, remember?), the Apache error log will contain the “Cannot find module ‘express’” error. Unfortunately due to Phusion Passenger nature, the server-wide error log is used instead of per-domain error logs. In this case, end-users will see the following message:

Bring Error Messages to the Browser

When developing an app, it’s very handy to see the error messages directly on the site – they are still getting logged. Go to the Node.js app settings screen and change the Application Mode to “development”. Next time an issue pops up, the error will be shown in the browser window. Like this:

Node.js and Windows

Node.js support is available in both Plesk for Linux and Plesk for Windows. But hosting Node.js apps on Windows has a few caveats you need to take into account. 

First, Node.js support in Plesk Obsidian is implemented with the help of the iisnode module (if you would like to learn more about the iisnode project, you can find the documentation here). Second, while in Plesk for Linux you can select a different Node.js version for every domain. In Plesk for Windows, a single Node.js version is used server-wide – you can select the Node.js version during the installation. 

Testing Node.js Support

Another difference is the location of the main entry point. In Plesk for Linux, it must be located in the parent directory of the domain’s “Document root”. In Plesk for Windows, it must be placed directly in the “Document root” directory.

To test Node.js support, let’s use the Express-based demo app from here. Create a directory called “node-express” on your domain using FTP access or the built-in File Manager. Then deploy the contents of the “node-express” GitHub repository. After that, click the “Hosting Settings” link (inside Domains -> Website name) and set the domain’s “Document root” directory to “node-express”.

Then, go to Node.js app settings and change the “Application Startup File” to “server.js”. Finally, install the dependencies using the “NPM install” button. Once the dependencies are installed, you can browse your site to make sure that the app is running. Some additional tuning of rewrite rules may be required, but as you can see, it’s possible to launch Node.js app even on Windows hosting.

…So that’s it, folks! Plesk Obsidian and Node.js support extension make hosting Node.js apps as simple as one, two, three. You can also read Php vs Node.js and Node.js vs Ruby on Railscomparison articles for more information. Now, give it a try and let us know how you did in the comments! 

Plesk 12.5 and Node.js

Plesk Node Js setup

During the last few years, Node.js has been steadily growing in popularity. On top of that, according to StackOverflow, JavaScript is today’s most popular programming language. If you are a Node.js developer, you may be curious whether it is possible to host Node.js apps on Plesk. The short answer is “yes, it’s possible”. In this article, I’ll explain how to set up the environment step by step using an Ubuntu 14.04 server with Plesk 12.5 for my demonstration. If you want, you can use other OSes or Plesk versions, but there can be the minor differences in commands and instructions.

Continue reading

Plesk on Docker

Plesk Docker Container

Docker has been a hot topic this year. Modern software should have an option to be installed as a Docker container. Not long ago we have created a Docker image for Plesk. This article describes how to install and use Plesk Docker container.

Continue reading

Authentication Schemes in Plesk – just say No to passwords

authentication schemes in Plesk - no more passwords

Using passwords for authentication has its caveats. Strong passwords are hard to remember, while weak ones are easily guessed. Once you have to keep track of dozens of passwords, committing them all to memory becomes unfeasible; you start writing them down (images of a passwords written on post-it notes stuck to the monitor make security specialists wake up in cold sweat), or reusing the same password for different services (even if it is a good one, recycling a password is far from ideal). Using a special application like 1password is always an option, but some may baulk at the $50 it costs to use the version for Mac. All this makes one wonder: how do I reduce the number of passwords I need to remember without putting security in jeopardy?

Starting with version 12, Plesk comes with a number of features enabling you to log in to the panel without using passwords. Most of the authentication schemes described further are enabled by Plesk extensions. To install one of those, log in to Plesk, click Extensions in the left-hand menu, and then click Extensions Catalog. In this article I will be providing links to the Extensions Catalog website to make it easier to find the extensions I will be talking about.

Continue reading

Extensions: IDE and APIs Hinting

A development process should be comfortable. It means that you should have an editor or an IDE that allows you to express your thoughts in a fast and easy manner. Of course, the editor or the IDE requires fine-tuning. If you are working on a new extension for Plesk, I suggest to take a look at PhpStorm. It’s a great IDE by JetBrains for PHP-based projects. Good news are that PhpStorm has a 30-days trial and you can try it for free. Out of the box PhpStorm does not know anything about Plesk extensions. And we’ll try to do the development of Plesk extensions a little bit more comfortable.

Continue reading

How to set up Django on Plesk

As a follow-up to the article about Ruby on Rails and Plesk I’ll try to explain how to organize Django hosting on Plesk.

We will use an Ubuntu 14.04 server and Plesk 12.0 for our experiments. I assume that you will get this configuration somehow.

Plesk may use Apache and Apache+nginx for serving of websites. In the scope of this article we’ll check how to setup Django apps hosting only for Apache without nginx.

Continue reading

Plesk 12.1.8 Preview

Plesk 12.1.8 early preview is available. This build is not for production usage, only for demonstration purposes.

Changelog

Preview release highlights:​

  • Fully reworked Databases screen. Many features were improved and many new were added. The most notable: 
Continue reading

Plesk and Ruby on Rails

Ruby On Rails and PleskIn this article I’ll try to explain how to run Ruby on Rails applications on a server managed by Plesk. Plesk itself does not support modern Rails apps natively. But this doesn’t mean that you cannot deploy Ruby On Rails apps to Plesk hosting.

We will use an Ubuntu 14.04 server and Plesk 12.0 for our experiments. I assume that you will get this configuration somehow. It’s possible to deploy Rails apps on different OS and using different Plesk version, but all further commands will rely on Ubuntu 14.04 and Plesk 12.0 capabilities. 

Continue reading

Plesk 12 and NAT Manager Extension

There might be cases when a Plesk server is located in a private network and it has only one internal IP address. In such cases, website visitors can access the hosted sites via the NAT technology. NAT translates public IP addresses into internal IP addresses and encapsulates this information in network packets.

Plesk uses one and the same IP address for various purposes. For example, an IP address is used for web hosting (Apache + nginx configuration files) and for DNS zone definitions. And here is a problem. In the former case, an internal IP address should be used, and in the latter case, an external IP address. Plesk UI shows only one IP address, but it does not let you configure the mapping (translation) of IP addresses.

Continue reading