Is it possible to write a node.js extension in C (not C++)?

noahlz picture noahlz · May 6, 2012 · Viewed 16k times · Source

A quick google search yields at least one tutorial for writing a C++ "Hello World" for node.js, but it's unclear if it's possible to write such an extension using only C. Assuming it is possible, what challenges / limitations would I face?

Answer

loganfsmyth picture loganfsmyth · May 6, 2012

You can write parts of your extension in C if you want, but you'll need at least a small bit of C++ code to glue together your C code with Node.

As you will have seen in your HelloWorld, extensions rely on the v8.h and node.h headers, which have all of the classes that Node expects. Without those, you won't be able to properly create the JS object to export back to Node.

That said, you can pretty easily just write a small set of C++ functions that just call C functions, and wrap some kind of C structure.