Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for npm start script #143

Closed
johngeorgewright opened this issue Jan 28, 2013 · 14 comments
Closed

Support for npm start script #143

johngeorgewright opened this issue Jan 28, 2013 · 14 comments

Comments

@johngeorgewright
Copy link

Hey there,

Is there any way of using nodemon with npm's start script?

I tried:

$ nodemon -x npm start

and

$ nodemon -x "npm start"

and also just nodemon on it's own, but I just get the help dialogue with no error.

@dejj
Copy link

dejj commented Jan 31, 2013

Wouldn't you rather put

"scripts": {
  "start": "nodemon app"
}

in your package.json and call it with npm start.
That of course means you'll have to pass what's in your start target currently to nodemon, but that's a different issue.

@johngeorgewright
Copy link
Author

Not a massive fan of that, as I use the same start script on development and production environments.

@dejj
Copy link

dejj commented Feb 1, 2013

nodemon checks if the "app.js" you want to launch exists as a file. So in order to run nodemon -x npm start, create a file named "start". I ran into trouble, when the nodemon couldn't terminate the process so as to release the server socket in time, however.
I tried, and the same happens with the "supervisor" package.

If your start parameters are complex, why not incorporate them in a .js-script of their own?

@johngeorgewright
Copy link
Author

Yeh, that's probably the way to go here. I was originally using Cake, but I guess I can probably have a re-think.

@toymachiner62
Copy link

I would also like to use nodemon to run $ npm start because I want it to also run the prestart script which lints my project.

Example:

// package.json snippet
"scripts": {
    "prestart": "eslint index.js",
    "start": "node index.js"
}

if i run $ npm start, it first runs $ npm prestart.
I want to somehow do this with nodemon so that it runs not only the start script but also the prestart script.

Any ideas?

@remy
Copy link
Owner

remy commented Nov 25, 2015

The pre and post hooks for npm aren't supported. The solution here would be to change the start value to nodemon index.js.

@toymachiner62
Copy link

That won't work exactly for me b/c I used npm start in production.

But that did spark a light bulb. I can do something like this:

"prestart": "eslint .",
    "start": "node index.js",
    "predev": "eslint .",
    "dev": "nodemon index.js"
}

and then $ npm start will work for prod and $ npm run dev will work for development.

BOOYA!

Thanks for your help.

@toymachiner62
Copy link

Crap i spoke too soon. It only runs the predev script on initial launch. Subsequent file changes only run nodemon again and not the predev npm script.

@nathanhleung
Copy link

Here was my solution:

"scripts": {
    "prestart": "eslint .",
    "start": "node app",
    "dev": "nodemon --exec npm start"
  },

Nodemon will automatically catch any errors with eslint and then restart on changes.

@VictorioBerra
Copy link

@nathanhleung Does that mean eslint will run even in production via "npm start" instead of "npm dev"?

@nathanhleung
Copy link

nathanhleung commented Oct 10, 2016

@VictorioBerra yes, since the prestart hook will run eslint. However, eslint will only run once if you invoke npm start directly (with the aforementioned config).

Alternatively, you could try this approach:

"scripts": {
    "predev": "eslint .",
    "dev": "npm start",
    "start": "node app",
    "nodemon": "nodemon --exec npm dev"
  },

You'd run npm run nodemon to lint on changes, and npm start directly to run the server without linting.

@VictorioBerra
Copy link

@nathanhleung I needed to add run into npm dev for npm run dev

@ORESoftware
Copy link

Are there hooks we can put in nodemon.json instead of npm scripts?

@weijyewang
Copy link

weijyewang commented Apr 18, 2018

the following npm start works fine for me

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon ./server.js localhost 8080"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants