Avnish kumar
Mar 22, 2021

--

AJAX with NodeJS using browser built-in XMLHttpRequest object.

Node requires a wrapper for the built-in http client to emulate the browser XMLHttpRequest object — node-XMLHttpRequest is a one.

AJAX allows web pages to be modified asynchronously by exchanging data with a web server behind the scenes. Which means that it is possible to update parts of a web page, without reloading the whole page.

Let’s see an example to call an API and get the data which can further be embedded within HTML and rendered to the user.

Typical request look alike
Snippet of response from the server

Modern Browsers can use Fetch API instead of the XMLHttpRequest Object and can accomplish the same task with minimal code.

--

--