0

I wonder if it is possible to use the "os" module internally in native module, without passing it over as a param from javascript.

It's one of the core nodejs/electron modules so I assume it should be available in native module internally some way or another.

2
  • 1
    I don't think any of the C++ code from node's os module is available to link against. You can call JS from C++, but it's by no means efficient -- see stackoverflow.com/a/11387695/1218408 for example. Most of what's in node's OS module is trivial to re-implement. Commented Sep 5, 2017 at 23:34
  • Thank you for two nice ideas! If you can provide further info on how to easily grab the OS module functions as C++ native code in the form of an answer, I will gladly accept it ) Commented Sep 7, 2017 at 13:39

1 Answer 1

0

Expanding on my comment:

As far as I know, none of node's "os" module C++ code is exported for use by other C++ code.

Executing JS from C++ is possible, but far from efficient. (See https://stackoverflow.com/a/11387695/1218408 for an example of how to do it.)

Most of node's "os" module is fairly simple, and you're probably better off re-implementing whatever you need. The source for it is here: https://github.com/nodejs/node/blob/master/src/node_os.cc

Another possibility is to call your C++ functions with the result of whatever JS function you need. For example, maybe myFunction(os.loadavg(), "hello"). Simple but also not super efficient.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.