-5

Sometimes I'm confused about the relationship and differences between Node js and Javascript. So what is the difference between node js and javascript?

  • *"Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser."* https://en.m.wikipedia.org/wiki/Node.js – luk2302 May 28 '22 at 08:03
  • Possible duplicate of [Differences between Node environment and browser javascript environment](https://stackoverflow.com/questions/23959868/differences-between-node-environment-and-browser-javascript-environment) – trincot May 28 '22 at 08:09

1 Answers1

1

Javascript is a language described in an ECMAScript specification.

To be used, that language needs some sort of run-time environment that provides a mechanism for loading code and then running it using a Javascript engine.

Nodejs is one such run-time environment (it runs a script specified on the command line).

A browser is another such run-time environment (it runs scripts embedded in HTML pages).

In addition to running scripts, each run-time environment provides it's own access to things outside of the strict Javascript language definition. For example, nodejs provides a fairly large run-time environment that offers functions for doing networking, for accessing the file system, doing crypto operations, running other programs, creating a server, accessing various things in the OS, etc...

Similarly, a browser provides its own run-time environment that includes things like accessing the DOM in a web page, making http requests to other servers, etc...

So, a run-time environment with an associated library plus a Javascript engine makes something you can actually run code in and do something useful. The strict Javascript language definition doesn't define any networking or file access or any way to communicate with the outside world. So, to be generally useful, a Javascript language implementation needs to be connected to some kind of run-time library. Nodejs is one such implementation of a run-time environment. It is commonly used for building and running either standalone scripts (like build tools) or for implementing servers (often web servers).

The actual engine that runs Javascript code can be shared among multiple different environments. For example, the V8 Javascript engine is used in the Chrome browser, the Edge browser and in nodejs. But, the run-time library that goes with the engine and the means of loading code is different for a browser vs. nodejs.

jfriend00
  • 683,504
  • 96
  • 985
  • 979