Search code examples
javascriptnode.jsbufferv8

Can't access "v8" outside of node.js repl


I needed to use the "v8" variable of node.js to serialize and deserialize some buffers. But I can't seem to access it outside of the Node.js repl. Here are some screenshots

This is accessing v8 inside of the node.js repl

this is trying to access v8 inside of a file

Are there any work arounds or ways I could use to access v8 inside of a file?


Solution

  • v8, in a Node.js REPL, is a pre-defined variable that is the same as the v8 inbuilt module.

    You can access the module through ES modules and CommonJS:

    // ES
    import v8 from "v8";
    
    // CommonJS
    const v8 = require("v8");