NodeJS simple HTTP server URL request handle
Its easy to set a simple server up, but what now. Now we need to handle requests. People are going to want to see something and we must show it to them.
So for this tutorial will use this as a base for setting up the server:
const http = require('http');
const port = process.env.PORT || 5000;
var server = http.createServer((req, res)=>
{
//Our code will go here
}.listen(port, ()=>{console.log('Server UP')});
This will set up the server on localhost:5000/ (5000 if there is no port set in the environment variable).
Now we will get the url the user requested with just one line.
var request = req.url
With this we can show what we want depending on what the user wanted, bellow is the final code.