Donβt comment on why you want to do this, or what might be more standard practice: here is the solution to your question ... Keep in mind that the type of quotes required by your command line may vary.
In your db.js export the init function. There are many ways, but for example:
module.exports.init = function () { console.log('hi'); };
Then name it like this, assuming your db.js is in the same directory as your command line:
node -e 'require("./db").init()'
For other readers, the init OP function could be called as you like, it doesn't matter, it's just the specific name used in the question.
LeeGee Apr 07 '16 at 15:36 2016-04-07 15:36
source share