I have written some classes in C++. I have used OOP. Now I want to use this classes in nodejs. I think it can be done in this ways:
Which of these solutions is feasible?
Note: I have seen nodejs-ffi module, but it seems to use built-in methods only. Is that true?
Lets assume that I have written this:
namespace Math
{
class Aljebra
{
int Abs(int);
}
}
Yes, it is possible in all the ways you think of.
You need to create binding of your C++ classes to Nodejs, see this question or here and here. If performance are not negligible, you might find issues like this one. Anyways, this is the fastest method.
Calling codes? I always call a functions, but if you wonder how to use modules like nodejs-ffi it's a big pain to use them with C++. All function names are mangled in C++, which means that your Math::Aljebra::Abs might actually be called _ZN4Math7Aljebra3AbsEi and that depends on the compiler you use. If your library contain mostly extern "C" function, usable.
There are many libraries for doing that. I prefer DBus. You can use it to communicate with many system daemons. Of course if you want to use it with your C++ code you need to write a DBus service to communicate to.
That depend. If you are not able to compile, just use existing library, second solution might be the only one. If there is a need to communicate many nodejs instances to each other within your C++ library, third solution might be better.
I've used Node.js and C++ a decent amount seperately - I spose I could see Node.js as being the server-side language and C++ being the client-side in a very conventional way. This, however, sort of voids a lot of the power of Node.js as a client-side language, which is one of the "hotter" features of the language - that it can do both.
Additionally, I'm not sure of the support C++ has for client-side web development stuff. It's such a robust language, I'm sure it's possible... but I think by the time you figure out how to implement the C++ with Node.js, you could've just re-written the functions you want to call in C++ in Node.js or some other more suitable language.