I am trying to speed up development by creating a generator using node.js. I want to be able to manipulate and generate node.js module files, add comments to the files and more.
Example: Generating the API endpoint user:
var mod = library.createFile("users");
mod.addFunction("findAll").params([...]).comment("commentSection");
Is there such a library or something similar?
It sounds like you want a Node module that writes other Node modules. I don't know of any such module.
I'm not an expert on this area but I think there would be 2 parts to such a module:
Parser - Parses existing module files into an Abstract Syntax tree, basically a data structure to represent your code in a structured way. You can then modify this tree to extend your code.
Code generator - Takes the AST from above and produces a pretty-printed string (the actual code) which can then be written out to a file.
Some of the following may help you:
Esprima, a parser for Javascript.
escodegen, an ECMASscript code generator.
jison, a A parser generator with Bison's API