2

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.

2

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

I'm just running node.exe. I'm not creating a package or running npm. Is there a general place to put an npm package that will always get executed when node.exe runs?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.