URL query

Report a typo

Imagine a browser's address bar. You need to send a GET request to your HTTP server with this information in the following order:

  1. animal - dog

  2. color - black

  3. name - pinky

And here is the server code:

http.createServer((request, response) => {
	const requestQueries = url.parse(request.url).query.split('&');
	const requestParams = Object.fromEntries(requestQueries.map((query) => query.split('=')));

	response.writeHead(200, {'Content-Type': 'application/json'});

	response.write(JSON.stringify(requestParams));

	response.end();
}).listen({
  port: 9999,
  host: '192.168.1.3'
});

Notice that you need to specify the full path, with a protocol, host address, and port.

Enter a short text
___

Create a free account to access the full topic