DEV Community

Cover image for NodeJS http homepage 20: request url with link menu
Falah Al Fitri
Falah Al Fitri

Posted on

NodeJS http homepage 20: request url with link menu


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

    }
Enter fullscreen mode Exit fullscreen mode

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

    }
Enter fullscreen mode Exit fullscreen mode

for 404 page

    else
    {

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

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

    }
Enter fullscreen mode Exit fullscreen mode

and, close it

    res.end();
Enter fullscreen mode Exit fullscreen mode

Thank for reading :)

Top comments (0)