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

--

--

--

Finalist student in Computer Engineering

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Ethereum Dapp with Vuejs app

How JavaScript Work

GDPR Cookie Consent JavaScript Plugin

GDPR Cookie Consent Plugin

React/Redux is EASY…tutorials are hard

Why and what I love about React.js

Creating an App Icon is Easy

MyVinyl app logo

Attach Screenshot into Mochawesome HTML Report in Cypress

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

More from Medium

Reactive JQuery using Vuex design pattern

End to end tests (E2E) with NodeJs, RethinkDB, and cypress.io

How to set up a form with reusable fields and automatic tests on push in Github branch simply.

Configure MongoDB Realm to perform CRUD operations in our app using GraphQL