Monday, 16 September 2019

Noob question on http.createServer and how it works

Apologies if this isnt the right place to ask this. Please re-direct me elsewhere if so.I only have web dev experience in Flask where we have to write specific view functions for each route. So if a particular route entered in the URL is not handled by a view function, then there will be an error.In contrast, for this code snippet:const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World\n'); }); Whatever route I give i.e. whatever I enter in the URL, I get a valid 'Hello World' response. So how exactly is this working - and how do I write specific functions for different routes?

Submitted September 16, 2019 at 09:02AM by ThiccShadyy

No comments:

Post a Comment