How to Install Node.js and Express on Ubuntu 20.04

Node.js based on the Chrome V8 Engine, it is a popular language used to build highly scalable applications. He has already involved in many projects, including Express.

Download Node.js

You need to download the latest version of Node.js by following command:

cd / tmp
wget http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz
tar xvf node-v0.10.32-linux-x64.tar.gz

Install Node.js

Run the following commands. They will install the JS node by copying everything from node-v0.10.32-linux-x64в /usr/local:

cd node-v0.10.32-linux-x64/
cp * /usr/local/ -r
cd ~

Now run node -v. If you see v0.10.32 then you have successfully installed Node.js.

Installation Express.js

What about the express lesson? First, you will need to run the following command to install the Express generator. Express generator helps you easily create your project.

npm install -g express-generator

Then, when it’ll be done, check if the Express generator is installed by running express -h. If successful, it will show you a list of available options.

Create your Project

While there are several options you can choose from, we will stick with the default when we create our project. To create a project, run the following commands:

express expressproject
cd expressproject
npm install

First, a new folder is created called expressproject. Inside it, you will see 2 files named app.js and package.json, and 5 directories called bin, node_modules, public, routes, and views. This will install Express for your project as well. Now you can run npm start your Express server. If everything is configured correctly, the following answer you’ll see

> expressproject@0.0.0 start /root/expressproject
> node ./bin/www

You need to navigate in your web browser the IP address of your VPS at port 3000. The URL looks like this (replace 1.2.3.4 accordingly):

http://0.0.0.0:3000

If successful, you will see Welcome to Express on the page in your browser!

Was this article helpful?

Related Articles