node js call function from command line
In your db.js, export the init function. There are many ways, but for example: Module.exports.init function () console.log(hi) Then call it like this, assuming your db.js is in the same directory as your command prompt: Node -e require("./db").init(). Dec 20, 2015. Writing Command-Line Applications in NodeJS.You will have to add bin manually, which tells NodeJS what your CLI app is called and what is the entry point to your app. Make sure you do not use a command name that already exists in your system. The complete solution for node.js command-line interfaces, inspired by Rubys commander.otherDirs.forEach(function (oDir) .Use the --harmony option when call the command, like node --harmony examples/pm publish.