node.js: URL-based requests

var http = require('http');var server = http.createServer(function(req, res) {var cat = req.url;if (cat == "/laptops"){res.end('Laptops Category');} else if (cat == "/smartphones") {res.end('Smartphones Category');} else if (cat == "/tablets") {res.end('Tablets Category');} else {res.end("Technology Store")}}).listen(8085);
node require.js
http://localhost:8085/
http://localhost:8085/laptops
http://localhost:8085/smartphones
http://localhost:8085/tablets

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Afonso Antunes

Afonso Antunes

Finalist student in Computer Engineering