DEV Community

Cover image for NodeJS http homepage 10: hello world
Falah Al Fitri
Falah Al Fitri

Posted on

3 2

NodeJS http homepage 10: hello world


Happy Coding

In this moment, we will created "Hello World" in NodeJS HTTP using a sandbox online, cause fast, effective and efisien.

Ok, let's write on

const hostname  = 'localhost';

const port      = 3000;
Enter fullscreen mode Exit fullscreen mode

then, load the HTTP module

const http = require('http');
Enter fullscreen mode Exit fullscreen mode

next, create http server

const server = http.createServer( function ( req, res ) {

    res.writeHead( 200, { 'Content-Type': 'text/html' } );

    res.write( '<h1>Hello World in NodeJS HTTP</h1>' );

    res.end();

} );
Enter fullscreen mode Exit fullscreen mode

and last, use listen method with callback function for display message

/* port, hostname, callback */
server.listen( port, hostname, function () {

    console.log( `Server running at http://${hostname}:${port}/` );

} );
Enter fullscreen mode Exit fullscreen mode

Thank for reading :)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs