Search code examples
node.jsv8

Does nodejs parse JavaScript before feeding it to V8?


V8 does not understand things like "require" and "setTimeout", but Nodejs does. Hence, am I right that Nodejs has its own parser/interpreter, that identifies the non-js tokens and processes them before feeding the rest of the JavaScript to V8?


Solution

  • Embedders of V8 add embedder-provided functions (and/or other properties) to the global object. They can use V8's embedding API to add features that are implemented in C++; they can also execute JavaScript files that define global functions and/or properties (just like you would in user-space). Node.js uses a combination of both techniques.

    See V8's docs for an introduction.