Skip to main content

Dedicated Server: Installation of JavaScript

This guide was created with the following products:

(Details may vary with products from different providers but the main concepts remain the same)

Introduction

This guide provides steps for the installation of Node.js, Deno and Bun. These commands must be executed via SSH, if you don't know how to connect to your server via SSH, please have a look at our Initial access (SSH).

Prerequisites

Before you install anything on a server, it is recommended to run the update command corresponding to your operating system to keep your server secure.

  sudo apt update

Installation

To begin, you need to decide which JavaScript runtime to install. There are plenty of online resources describing each one in much detail. But you can also read this guide because it will include basic usage commands and code examples. We can recommend using NodeJS as it is one of the most widely used and a very popular choice.

Installing Node.js Runtime

You can install Node.js via your Linux distro package manager or using nvm. We recommend using apt as this is usually easier.

Run the following command to begin installing Node.js via the package manager.

apt install nodejs -y

To install Node.js packages for your projects, you will also need to install the npm package manager.

apt install npm

Update Node.js to latest version

Running node -v will show you the installed version of Node.js. This is usually not the latest one and thus you'll need to update it to get the latest features. Luckily, the npm package n provides a very easy way to do this.

Firstly, we'll need to install it by running npm install -g n and then we can run n [version], replacing [version] with the version number of choice, to install any version of Node.js.

tip

It is generally recommended to keep your installation on the latest Long Term Support version. You can do so by running n lts.

Running Node.js & npm

Npm is the official package manager of Node.js. You will use it for installing any packages from the internet.

note

You can find all npm packages on their website.

Creating a new project

Every time you want to start a new Node.js project, you need to make a new directory for it (mkdir [project-name]) or cd into an empty folder and run the npm init command to begin the setup. This will ask you for some basic info for creating a package.json file. This will be the "config" file for running Node.js.

After initializing the new project, you can make a new file called index.js and write code inside it. As an example, we will create a simple http server on default port 80 which replies with a test message when accessed via localhost. This can be seen below.

const http = require('http')

const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('Hello from ZAP-Hosting Docs =)')
})

server.listen(80)

Now you can run the provided code with the node . command and check the results by going to localhost:80 in your browser.

tip

Installing external packages from npm is done with the npm install [package-name]

By following this guide, you will have successfully installed one of the popular JavaScript runtimes on your Linux server.