How to run a script when starting the Node.js console?
Is there a way to configure the Node.js console window (node.exe) to run a script on startup?
I'd like to do some minor initialization automatically each time, such as setting variables and colors.
It's not sufficient to just run node.exe myinitscript.js
. That will run the script and then exit.
I'd like to run the script, and then remain in in the console environment.
The easiest way would probably be to create your own script that starts the repl
instead. Create a script with:
global.something = 'blah';
require('repl').start({});
That will do some init and create some globals or whatever, and then run the repl, just like if you ran node.exe
directly.
Try setting the start
or the predeploy
property of the scripts
object of your package.json
.
The start
property: The start-up script for the package. When running npm start
this script will be called.
The predeploy
property: The pre-deploy script for this application. This script will run before a snapshot of your package has been created. It can therefore be used to compile and optimize assets before it's upload to your application.
For your reference, here's a cheatsheet for the general syntax/structure of the package.json file.
http://browsenpm.org/package.json
链接地址: http://www.djcxy.com/p/87378.html上一篇: Webpack手表输出格式