ADVERTISEMENT
ADVERTISEMENT

Home » Node.js

Say 'Hello, World' from server by Express.js (Node.js)

In this Node.js article, we are going to learn how to display ‘Hello world’ from Server-Side using Express.js?
Submitted by Manu Jemini, on November16, 2017

Node.js is one of the most famous servers in the world. It’s easy and fast. It requires only one-step installation. Node.js is a JavaScript server-side framework.

But, what gives it much more developing freedom is express.js. Here, let us conquer some of the most feared concepts. Its works on Node Package Manager, its abbreviation is "npm".

One does not need to install "npm" separately as it comes with the Node itself. Below is a quick tutorial on the setup of your developing environment.

Installation

  1. Make a google search of Node.js download, click on the first link.
  2. Click on recommended version of node.js. [Link: Download Node.js]
  3. After downloading, open the setup file, which you have just installed.

It will ask certain things and then done.

Initiation Part

Open your command prompt (if in windows). Type npm init and answer few more questions. It will take few minutes depending on your connection. After that open, the comfort of our favourite editor and in that directory make a.js file.

Your server File

var express = require('express')
var app = express();
app.get('/', ( req, res) => {
	res.send("Hello, World")
})
app.listen(3000,() => {
console.log("Server is running on port 3000")}

Here we have come up with a very fundamental server in express.js,

  • We tellexpress to include an express library and store its reference in the variable express.
  • Second-step is to tell the express library to quickly initiate a server for us.
  • Express not only make a server but also give us a reference to do lots of manipulation.
  • Then, we have to tell express to listen on the port 3000 after having a listener for the gets request.

Run IT

  • Open your command prompt in the project directory and type "node server.js"
  • Open your Browser, type "htpp://localhost:3000/"

The output would be,

Node.js Example to print Hello world
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.