Last updated Feb 23, 2021

Hello world in Node.js with Express Framework (Updated)

Create your first Express app in Node.js — Hello World!

Hello world in Node.js with Express Framework (Updated)

Howdy, coders, Hope you doing well!🙂

In the previous getting-started-with-node.js post we covered some basic introduction about node.js,

In this tutorial, we will take one step ahead and will create first hello world program in node.js with using the express.js framework.

This article is aimed for beginner developers and anyone interested in getting up and running with Node.js

If you don’t have knowledge of node.js then please check getting-started-with-node.js article first else continue here.

so, let’s get started…

How to Create First App in Node.js

Step-1: Install Node.js for your specific platform(Windows, Linux or macros)

Just go to nodejs.org in your browser address bar and you should be good to go, the home screen will automatically detect what you want, as I am running windows on my machine it will show respective version of node.js available for Windows operating system. go ahead and download and install in your machine, This will give you the tools needed to run a server on your local machine.

Step-2: Open command prompt and type:

mkdir helloworldapp
cd helloworldapp

Above commands will create a blank directory with name “helloworldapp“ and then move to that directory.

Type following command to initialize your app:

npm init

This command will ask you to enter a number of things, you can enter it your way except this one:

entry point: (index.js)

You need to change this to:

entry point: (index.js)  app.js

This will create package.json file in your “helloworldapp” project folder. this file will contain all packages you have downloaded for your projects with specific version details.

To learn more about NPM please click here.

Step-4: Install Express in project directory

now you’re thinking what is express right?

What is express?

Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
-

It is an open source framework developed and maintained by the Node.js foundation

So, to install express go to  command prompt and type following command:

npm install express --save

This will install the latest version of the express framework for your project, now you will be able to see node_modules folder in your project root directory, it contains all dependencies required for the express framework and –save command  will save the package to your dependencies list, located in the package.json file

Step-5: Open your text editor and create an app.js file in root directory and write below code:

var express = require("express");
var app = express();
app.get("/", function(req, res) {
  res.send("Hello World!");
});
app.listen(3000, function() {
  console.log("listening on port 3000!");
});

Here we have included express package which we have recently installed with using required method in the first line, by assigning module to variable here we can make use of its predefined set of tools.

The listen method starts a server and listens on port 3000 for connections.It responds with “Hello World!” to get requests to the root URL (/). For every other path, it will respond with a 404 Not Found

Step-6: Run the app

Type below command:

node app.js

this command will start listing your server on 3000 port, to view open your browser and go to http://localhost:3000 it will show result printed “Hello world” in browser and also you will be able to see “listening on port 3000!”  message in your terminal.

👍That’s it, you’re done. You have successfully created your first Node app.

Conclusion:

Thanks for reading.

Do let me know If you face any difficulties please feel free to comment below we love to help you. if you have any feedback suggestions then please inform us by commenting.

Don’t forget to share this tutorial with your friends on Facebook and twitter.

Tags

Available for projectsLet’s build together

Need this built properly,
not just explained?

I take on Angular and NestJS work directly — auth systems, multi-tenant SaaS, API rewrites and the deploy pipeline underneath them. You talk to the person writing the code.

Projects delivered
20+ Projects delivered
Angular • NestJS
7+ years Angular • NestJS
Average reply time
1 day Average reply time

What I can help with

  • Auth and permissions systems
  • Multi-tenant SaaS foundations
  • API design and rewrites
  • Deploy pipelines and VPS setup
  • Bug fixing and performance optimization
Send me a message

Tell me about your project and I’ll get back with a realistic scope and price.

Turn
Your Ideas
Into Reality

Stay in the loop

Get the finished tutorials, projects and resources in your inbox.

Join 5,000+ developers and get new tutorials, source code, product updates and exclusive content — straight to your inbox.

  • No spam
  • Useful content only
  • Unsubscribe anytime

Subscribe to TutsCoder

Be the first to get new tutorials, projects and tips.

Join 5,000+ developers already learning with us.

Learn
Build
Grow

Discussion

Comments

Share your thoughts, ask questions or suggest improvements. Let’s learn and grow together!

Loading comments…

Join the discussion

Sign in to join the discussion. Your account also keeps your saved tutorials and path progress.