loading...
Cover image for NodeJS http homepage 10: hello world

NodeJS http homepage 10: hello world

antelove19 profile image Falah Al Fitri ・1 min read

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;

then, load the HTTP module

const http = require('http');

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();

} );

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}/` );

} );

Thank for reading :)

Posted on by:

Discussion

pic
Editor guide