Is there a way in Node.js to define a "Standard Library", which is automatically executed at the start of every Node.js App?
For example:
//stdlibrary.js
function sayHello(){
console.log("Hello World!");
}
//app.js
sayHello(); //without including the stdlibrary.js!
Hope my question is clear.
Thanks for your help!
Update
I´m looking for something like the auto_prepend_file in PHP. Hope there is something similar to this.
Yes, this is simple to do. Just edit the src/node.cc file to include an option for an autorequire file, and then modify the node::Load code to handle the option. You probably also need to change the javascript in src/node.js.
Rebuild, test and you are done.
Or you could probably just hack this into src/node.js by having it eval a string that requires your library and then evals the actual script file mentioned on the command line.
There's no such thing in node.js, this kind of magic is not transparent and because of this reason gladly avoided by the most software products.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With