Podcast | How to Host Node.js Applications on Plesk Obsidian

As an open-source, cross-platform runtime environment for developing server-side web applications, Node.js has garnered a huge amount of popularity and support. Using the widely used JavaScript language, it assists web developers of all sizes to write lightning-fast applications, whether you’re supporting a small side project, or a government agency.

Podcast Joe Casabona

Why Use Node.js

Now, you might be wondering why you’d use something like Node.js instead of PHP or Ruby on Rails. Over on the Plesk blog, we have several articles comparing Node.js to each of them, but here are some of the highlights:

  • The most significant difference between Node.js and PHP is that Node.js is a client-side language, meaning that processing is done in the browser using Javascript. This gives you a lot of flexibility for tasks you can perform. Generally, Node.js can also at least seem faster. You’re doing more in the browser, and less on the server, which means your applications can be more responsive going forward.
  • But PHP is quite powerful and a great connector if you’re doing a lot of server-side work. It’s reliable and has been around a long time. It worked really well with MySQL, and powers popular web applications like WordPress.
  • Ruby on Rails is more of a website framework with multiple languages and a complex architecture. It’s built for quick site development and has its own integrated web server. But debugging is difficult and it can be inflexible at times.

What you choose is really up to you and what’s best for the task at hand. But if you’re working on the web, chances are you’ll need to use Node.js at some point, if you haven’t already.

If you are considering providing Node.js application hosting as a service to your customers, or if you would like to use Plesk to automate hosting Node.js applications you are developing, we’ve got good news for you.

Plesk comes with a Node.js extension that allows you to install and manage apps quickly and easily. Other key functions include:

• Using the latest releases of Node.js (LTS and Current),
• Choice of package manager: NPM or Yarn,
• Viewing application logs in Plesk web interface using Log Browser,
• Easy to use web interface for other related management functions

In this episode, we’ll describe in detail how to work with Node.js apps in the context of Plesk Obsidian, the latest version of Plesk.

One more note: we have a step-by-step tutorial with screenshots that we’ll link up in the show notes. This episode will give you a high-level overview of what you need to do, and what to consider.

Get Node.js Extension

The first thing you need to do is install Plesk Obsidian. You can use either a Linux distro or Windows; the tutorial on our site used Debian. As you work with Node.js and Plesk, just note that there could be some minor differences if you run with a different OS than the tutorial you’re using.

Assuming Plesk is already installed, we can now install the Node.js extension.

After you log in to Plesk, you’ll want to 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, you can try to host a sample Node.js app, such as a “Hello, World” app. You can find one from Github in the notes of this episode. 

Copy/pasting content from the App.js file manually is an option. However there’s another Plesk extension instead worth exploring — the Git extension. 

Now, to use the Git extension, you have to create a domain with hosting, which is called a subscription. Then, you need to simply create a target directory where the app will be stored. From there, you’ll be able to install the Git extension. Then you need to set up a local repo to pull the code from. You’ll want the local repo to mirror the remote one so the code can be deployed correctly. 

Again, see our tutorial for step-by-step actions with screenshots.

Differences Between ‘Document Root’ and ‘Application Root’

As you set up your application, you’ll see references to both “Document root” and “Application root.” It is important to note that they are not always the same thing. 

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…this is likely your HTML, CSS, and image files.

The “Application root” is the root directory where the app itself is located. This, for the purpose of this episode, is where the executable Node.js code lives. 

In most cases, the “Document root” is a directory inside the “Application root” directory.

You can change the Document root in Plesk by going to “Domains”, selecting your website and going to “Hosting Settings.”

From there you can change the existing Document root to match the repo name, and adding “slash public” to the end — but again, note that your milage may vary depending on your own server environment and code repo.

Enable Node.js Support

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

You will then want to visit the “Application URL” to make sure that the app is running. If you see the expected results (in the example mentioned, “Hello World” will show on the screen), you’ve successfully installed and enabled Node.js.

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. 

You will need to install dependencies separately for them to work. 

Installing Dependencies

You do this by initializing the app first. Luckily, in Plesk, you can install dependencies by clicking the “NPM install” button. This will install all app dependencies according to the package.json file.

Note: You can also use Yarn package manager. The extension will attempt to determine the package manager you need based on the application files. Or you can specify it explicitly in the extension interface.

Then, you need to tune the app startup file. Plesk uses the Phusion Passenger application server to serve Node.js apps. You can find the sample code in the show notes!

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.

Debugging

Next up, let’s talk about debugging. Knowing how to debug Node.js apps in case any issues appear is essential for any Node.js developer. Here are a few tips that can save you a lot of headaches: 

Viewing Hosted Application Logs

The first thing to do when troubleshooting a Node.js app is to check the log files. To find the log records including console output for your application, open “Log Browser” for your website. You can focus the listed records using the dropdown at the right.

Bring Error Messages to the Browser

When developing an app, it’s convenient to see the error messages directly displayed 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.

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 in the show notes). 

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 – so you can select the Node.js version during the installation.

There are a few other small differences. For example, 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. But it is possible to run Node.js on Windows!

Key Takeaways

So there you go. A highlevel overview of: 

  1. What Node.js is
  2. How it compares to PHP and Ruby on Rails
  3. How to install it using Plesk Obsidian
  4. Working with dependencies
  5. Debugging
  6. Installing it on Windows

Do you have more questions about using Node.js on Plesk? Let us know!

The Official Plesk Podcast: Next Level Ops Featuring

 Joe Casabona

Joe is a college-accredited course developer and podcast coach. You can find him here.

Did you know we’re also on Spotify and Apple Podcasts? In fact, you can find us pretty much anywhere you get your daily dose of podcasts. As always, remember to update your daily podcast playlist with Next Level Ops. And stay on the lookout for our next episode!

One comment

  1. Great podcast. Subscribed!

Add a Comment

Your email address will not be published. Required fields are marked *

We are Plesk

Value simplicity and automation too? We help devs, sysadmins, and resellers run, manage and secure via our control panel solutions, extensions and hyperscale opportunites. Discover how you fit with us.

GET LATEST NEWS AND TIPS

  • Yes, please, I agree to receiving my personal Plesk Newsletter! Plesk International GmbH and other WebPros group companies may store and process the data I provide for the purpose of delivering the newsletter according to the Plesk Privacy Policy. In order to tailor its offerings to me, Plesk may further use additional information like usage and behavior data (Profiling). I can unsubscribe from the newsletter at any time by sending an email to [email protected] or use the unsubscribe link in any of the newsletters.

Related Posts

Knowledge Base

Plesk uses LiveChat system (3rd party).

By proceeding below, I hereby agree to use LiveChat as an external third party technology. This may involve a transfer of my personal data (e.g. IP Address) to third parties in- or outside of Europe. For more information, please see our Privacy Policy.

Search
Generic filters
Exact matches only
Search in title
Search in content
Search in excerpt