Untitled

 avatar
unknown
plain_text
9 days ago
1.2 kB
3
Indexable
const http = require('http');
const server=http.createServer((req,res)=>{
    console.log(req.url);
    console.log(req.method);
    const url = req.url;
    const method = req.method;
    if(url==="/" && method==="GET"){
        res.setHeader('content-type','text/html');
        res.write(`<!doctype html>
           <html>
            <head>
                <title>Routig in Node JS</title>
            
            </head>
            <body>
                <form action= "/message" method = "POST">
                    <input name = "sampleTxt" placeholder="eneter the name">
                    <button> Submit</button>
                </form>
            </body>
           </html> `);
           return res.end();
    }

    if(url==="/message" && method ==="POST"){
        res.setHeader('content-type','text/html');
        res.write(`<!doctype html>
           <html>
            <head>
                <title>Routig in Node JS</title>
            
            </head>
            <body>
                <h1>Hello from server</h2>
            </body>
           </html> `);
           return res.end();
    }
});
server.listen(4000);
Editor is loading...
Leave a Comment