For testing purposes, I want to reference on a js primitive value.
Is it possible with help of node.js c++ addon? How to do it?
let addon = require('./build/Release/mymodule.node')
let num1 = 999
let num2 = addon.ref(num1)
num1 ++
console.log(num1) // 1000
console.log(num2) // 1000
(V8 developer here.)
V8 doesn't make this possible, neither with nor without Node C++ addons. The basic JavaScript rule that there are no references to primitives is baked very deeply into the engine design. If you wanted to change that, you'd have a new language and would have to write a new engine for it.
So whatever your "testing purposes" are, I would recommend to find and pursue some other approach.