• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer
  • Home
  • Java Tutorial
  • Java Posts
  • Node.js
  • Spring Core
  • Algorithms
  • Docker
  • Blogging
  • Misc
Tech Stack Journal

Tech Stack Journal

Basic web application in Node.js to return text

April 13, 2020 by Admin Leave a Comment

Here we write a basic web application in Node.js that serves static text to the client’s HTTP requests.

var http = require('http');
var server = http.createServer();
server.on('request', function(request, response) {
    response.end('Hello World');
});
server.listen(8080);
console.log('Server started. Hit http://localhost:8080');
  • Added an event listener on the server variable that listens to the request events.
  • The event listener takes a callback function with two arguments, request and response.
  • If there is a request, node.js will raise a request event adding the respective request listener to it
  • The request listener nothing but the callback function, will gets executed to return “Hello World” to browser.

Filed Under: Node.js

Previous Post: « Why does a while loop blocks the event loop?
Next Post: Callback Function in Node.js »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


Primary Sidebar

More to See

Arrays.asList in Java Examples

February 21, 2021 By Admin

[Solved] Why List.add throws UnsupportedOperationException in Java?

February 20, 2021 By Admin

Secondary Sidebar

Categories

  • Algorithms
  • Blogging
  • Docker
  • Java
  • Misc
  • Node.js
  • Spring Core
  • Windows

Archives

  • February 2021 (6)
  • January 2021 (1)
  • December 2020 (1)
  • September 2020 (2)
  • August 2020 (5)
  • July 2020 (4)
  • June 2020 (1)
  • May 2020 (4)
  • April 2020 (22)
  • November 2019 (3)
  • September 2019 (2)
  • August 2019 (6)

Footer

Navigation

  • Home
  • Java Tutorial
  • Java Posts
  • Node.js
  • Spring Core
  • Algorithms
  • Docker
  • Blogging
  • Misc

Recent

  • How to Make File Explorer Open to This PC instead of Quick Access in Windows 10
  • Arrays.asList in Java Examples
  • [Solved] Why List.add throws UnsupportedOperationException in Java?
  • How to Convert an Array to List in Java?
  • How Many Spaces in a Tab?

Search

Copyright © 2021 · Tech Stack Journal · Log in