DEV Community

loading...
Cover image for NodeJS http homepage 20: request url with link menu

NodeJS http homepage 20: request url with link menu

antelove19 profile image Falah Al Fitri ・1 min read

Happy Coding

This is next step from previous post

In this post, we will add content home, about and 404 page with link menu using reg.url for checking

Ok, let's write on again.

for home page

    if ( req.url == '/' )
    {

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

        res.write( '<h1>Hello World in NodeJS HTTP</h1>' );
        res.write( '<p>NodeJS easy-to-learn</p>' );        

    }

for about page

    else if ( req.url == '/about')
    {

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

        res.write( "<h1>About me</h1>" );
        res.write( "<p>I am developer</p>" );
        res.write( "<p>I love programming</p>" );        

    }

for 404 page

    else
    {

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

        res.write( '<h1>Page not found</h1>' );

    }

and, close it

    res.end();

Thank for reading :)

Discussion (0)

Forem Open with the Forem app