How is JavaScript able to run on the server side?

How is JavaScript able to run on the server side?

We all grew up hearing that JavaScript is a client-side language, but nowadays, people (even me) use JS on both the client and server sides. So, how is that possible?

Here's the tech side:

In the earlier days, JavaScript was primarily designed for client-side scripting within web browsers, and browsers provided a JavaScript runtime environment but lacked the necessary APIs and capabilities for server-side operations like file I/O, network access, and system interactions.

In 2009, Node.js was introduced. It was a breakthrough as it introduced a standalone server-side JavaScript runtime, enabling JavaScript to be used outside the browser environment. But how? How is Node.js able to run on the server side?

Node.js enables server-side execution by providing a standalone runtime environment (meaning it gives JavaScript the ability to run on a server or computer without needing a browser) by leveraging the V8 JavaScript engine (developed by the Chromium project for the Google Chrome browser). The V8 engine compiles JavaScript into machine code, enabling efficient server-side execution. Also, Node.js operates on an event-driven, non-blocking I/O model, allowing for the concurrent handling of multiple requests. This enables JavaScript to run on the server in a scalable and effective manner.

This is how JavaScript is able to run on the server side. Hope you got an idea. So happy coding 😀.