npm: how to run test & lint on each change?
So you should have a definition of the start in your package.json to first run lint, then test then the actual run server. You can find an example in following post: http://substack.net/task_automation_with_npm_run
you should run the 'npm run monitor' command to start the monitoring and the restart should call the npm run start script.
but basically you want to have (based on your package.json)
"scripts": {
"start": "npm run lint & npm run test & node ./myfile.js",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"monitor": "nodemon ./bin/www"
.....
Related videos on Youtube

MarcoS
I'm a sailor. I love roaming in the Mediterranean sea on any wood piece you can stick a mast and a sail on. In my spare time I do software engineering in Turin, as a full-stack developer. I start my coding ages ago with x86 assembly; then I go with C, bash, Perl, Java; Android; currently I do MEAN stack: MongoDB, Express.js, Angular.js and of course Node.js. Obviously on the shoulders of the GNU/Linux O.S..
Updated on September 14, 2022Comments
-
MarcoS 3 months
I am using a bare
npm
( nogrunt
/gulp
) approach to develop my new MEAN project.
My config is like the following:File package.json:
... "start": "nodemon ./bin/www", "lint": "jshint **/*.js", "test": "mocha --recursive", "dependencies": { ... }, "devDependencies": { ... },
Before starting, I run an
npm start
andnodemon
starts monitoring my project tree for changes, triggering a restart after each source file change.
So far so good.But what if I'd like to include - say - the
lint
and/or thetest
stages on each restart?
I didn't find any clue nor in the nodemon page nor in the npm one... -
MarcoS about 7 yearsWhat is
./myfile.js
? -
sagie about 7 yearsyour app.js file that you start your application with.
-
MarcoS about 7 yearsI don't understand what you mean, sorry: if I call
npm run monitor
, hownpm start
will be called? -
sagie about 7 yearsIf thats how you startup your app than yes.
-
sagie about 7 yearsSee github.com/remy/nodemon#running-non-node-scripts so you can have nodemon --exec "npm run start"
-
MarcoS about 7 yearsHmmm... I suppose I'll drop "monitor" and will use
"start": "npm run lint & npm run test & nodemon ./bin/www"
... :-) -
sagie about 7 yearsthat might end up as an endless loop as you will run nodemon from nodemon. so just make sure that doesn't happen.
-
MarcoS about 7 yearsLet us continue this discussion in chat.
-
sagie over 4 years@Sobiaholic meaning? error? what? for me it works great even 3 years after I answered it.