I know it is possible to write a command line interface with node but all examples i have found so far is simply passing parameters in the terminal that will execute a node script and then immediately exit the node environment, loosing all its variables and state.
For example if i have an api with a login function and another function which depend on the auth state i want to do everything inside node.
I know this way works but there must be a better way that is more straight forward than writing require in the terminal every single time?
$. node
$. let api = require('./myApi')
$. api.login()
$. api.fetchData()
这似乎符合您的要求: https : //www.npmjs.com/package/node-repl
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.