How to install ExpressJS on Debian 11?

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

In this post, you will learn how to install ExpressJS on Debian 11.

Hello, developer friends and all. If you are just starting in front end development it is convenient some tutorials that may seem easy but at the beginning to a novice is complicated.

What is ExpressJS?

Express is a minimalistic development framework for Node.js. Thanks to it, we can have a light, fast and very useful framework.

One of the advantages of using Express is that it provides us with functionalities such as routing, options to manage sessions and cookies, etc. All in a very fast and easy way.

Express was initially released in November 2010 and continues to develop and improve with each version. We are going to install it on Debian 11 and so ready for you to start playing with it.

Installing NodeJS on Debian 11

To use Express.js, we need to install NodeJS first. For this, we have several ways, but I will install the latest stable version.

To complete this, open a terminal and first update the operating system

sudo apt update
sudo apt upgrade

Thereafter, add the 16.x branch repository of NodeJS.

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

Then, just run the following command

sudo apt install nodejs

Then check the installed versions of NodeJS and NPM to verify if the installations have been successful.

node --version
v16.13.2
npm --version
8.1.2

Install ExpressJS on Debian 11

Now you have to install Express.js and to do it globally you have to run

sudo npm install -g express
1.- Install ExpressJS on Debian 11
1.- Install ExpressJS on Debian 11

Then create the project folder:

mkdir project

Access the folder:

cd project

Then initialize the project

npm init -y

Install Express.js for this project locally

npm install express

Now create a sample file:

sudo nano app.js

And add the following

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
    res.send('Hello. Welcome to this blog')
})

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})
2.- Creating a new app on Express.js
2.- Creating a new app on Expressjs

Save the changes and close the editor.

Now run the project with this command

node app.js

Sample Output:

Example app listening at http://localhost:3000

Now open a web browser and go to the indicated address or your server address.

3.- Express.js on Debian 11
3.- Expressjs on Debian 11

Enjoy it.

Conclusion

Express.JS is a tool for NodeJS developers. In this post, we have explained to you how to start a project with these tools.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook