In this tutorial, we will explain how to install Node.js and create your first Express JS application on an Ubuntu 16.04 VPS. Express is an open source, fast and flexible web development framework for node.js and provides a robust set of features to develop web and mobile applications. Express is to Node.js what Ruby on Rails is to Ruby. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 16.04 VPS.
The following instructions assume that you don’t have Node.js installed on your machine.
We will install the Node.js version 4 LTS Argon from the nodesource (formerly Chris Lea’s Launchpad PPA) repository.
The command bellow will add the nodesource signing key to your apt keyring, add the deb.nodesource.com repository to your apt sources and run
apt-get update to update the package sources.
[user]$ sudo wget -qO- https://deb.nodesource.com/setup_4.x | sudo bash -
When the command above completes, install the Node.js package with:
[user]$ sudo apt-get install -y nodejs
To check the Node.js version installed on your machine run:
[user]$ node --version
The output should be similar to the following:
The easiest way to create a new Express projects is a tool called an Express application generator. The application generator tool (express-generator) will help you to quickly create an Express application skeleton.
Install the express-generator globally using the following command:
[user]$ sudo npm install express-generator -g
You can check the command options with the –help option:
[user]$ express -h Usage: express [options] [dir] Options: -h, --help output usage information -V, --version output the version number -e, --ejs add ejs engine support (defaults to jade) --hbs add handlebars engine support -H, --hogan add hogan.js engine support -c, --css add stylesheet support (less|stylus|compass|sass) (defaults to plain css) --git add .gitignore -f, --force force on non-empty directory
You can now create a new express application using the express generator tool:
[user]$ express myNewApp
The command above will create a new barebone express application in the myNewApp directory.
Switch to myNewApp directory and install all the default dependencies using the npm tool with the following commands:
[user]$ cd myNewApp [user]$ npm install
Once all the dependencies are installed start the application with the following command:
[user]$ DEBUG=myNewApp:* npm start
You should now have an express application running at:
http://localhost:3000 . Open the link in your web browser and you should see something like below:
Express Welcome to Express
That’s it. You have successfully created your first Express JS application on your Ubuntu 16.04 machine. For more information about Express, please refer to the official Express documentation.
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install this for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.