• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Setting up an Express.js Web Server on Ubuntu 16.04 LTS

How VPS by How VPS
January 1, 2020
in Linux
0
0
SHARES
22
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Installing Node.js
  2. Installing Express
  3. Want to contribute?


In this tutorial, we will be installing a basic Express.js web server, using Node.js, a Javascript runtime based on Chrome’s V8 engine, on our Vultr VPS running Ubuntu 16.04. If you don’t know, Express.js is a minimal and flexible Node.js framework that gives you the power to write web applications. It really showcases what Node.js can do, in terms of web development. So without further ado, let’s get started!

Installing Node.js

To begin, you’ll first need to install Node.js, which will be the backend for our Express site. To install it on Ubuntu 16.04, we’ll first need to add the repository for the latest version. To do that, type the following:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

What this does, is it grabs the latest 8.x packages from nodesource.com, and sets it up as an APT repository. When that’s finished, run the following to install Node:

sudo apt-get install -y nodejs build-essential

What this is doing is installing Node.js itself, and it grabs build-essential, which are some tools you may need when compiling modules. When that is done, we will create a new Node project. First, make sure you are in your /home directory.

/home/yourname

To check, just type pwd in your terminal, and if you see /home/yourname, then you’re all set! Then, we will be using npm’s init feature to create a package.json where all of our modules will be kept track of. To do that, type npm init in your terminal. Follow all of the prompts, and you will see this when you are finished:

{
  "name": "example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo /"Error: no test specified/" && exit 1"
  },
  "author": "rich",
  "license": "MIT"
}

Then, click enter to confirm.

Installing Express

Next, we will install our Express module. To do that, just type:

npm install express

Wait until it finishes installing.

To make life easier, we will use a neat little module called express-generator. What this will do is it will generate a skeleton website for us, making out life a lot easier. It takes care of the basic stuff, like routes and such. To install Express Generator, simply type:

npm install express-generator -g

We specify the -g flag, which means that it will be global, and we can use it throughout our system. Once we finish installing it, we have to make a decision. We have to choose what rendering engine we want to use for our project. For brevity, we will use ejs in this tutorial, which is an awesome rendering engine that I highly recommend you look more into. To setup our bare project, just type:

express -v ejs mysite

This will make a new folder inside of our existing project, with the name mysite. Now, to make sure we have all of the required modules for the project, run the following command.

npm install

Now that we have the basic website setup, we can start it! To start the website, with a basic port, simply type:

DEBUG=mysite:* npm start

The website will now start. The only issue is, you won’t be able to see the website, since you are using a terminal. In order to view the example page, we will have to specify an IP address to the HTTP server, which will be the IP address of our VPS. To obtain your IP address, simply go to your Vultr VPS panel, and click on the servers tab. It should be right below your server name, on the bottom. For example: “1024 MB Server – yourIP”. Copy that IP address, and keep it close, because we will need it. Then, go back to your server, and change your directory to the bin folder.

cd mysite/bin

This is assuming you created the folder in your home directory. Edit the file inside: the www file. To do that, we will use the built-in editor, Nano.

nano www

Once inside, navigate to this line:

server.listen(port);

Add your IP address into that line. Edit it so it looks like this:

server.listen(port, 'your ip here');

Then, press “control-o” on your keyboard, and “enter” to save. Press “control-x” to exit. Now, we are all set to start our server. Simply type the same command we typed earlier to test it:

DEBUG=mysite:* npm start

The console will now output the port it is listening on. Keep track of this port, as you will need it. To view your site, open your web browser and navigate to the following URL.

http://yourIP:port

For example, it might look like this:

http://192.0.2.0:3000

If all went well, you will see “Welcome to Express” on your screen!

And you’re done! You have created your first Express site with Node.js, running off a Vultr VPS. To learn more about Express, and what you can do with it, I recommend going over to their site at http://expressjs.org, and the EJS website at http://ejs.co, where you can read up on the documentation, and create your own killer site!

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

Installing Golang on Ubuntu 14.04

Next Post

Securing SSH on Ubuntu 14.04

Next Post

Securing SSH on Ubuntu 14.04

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet