how to run nodemon in windows from package.json
Asked Answered
G

2

6

I'm following a VUE tutorial on a mac (shown in youtube).

In my src/app.js I have only console.log('hi');

The start command for the Mac in package.json as shown on the youtube video is:

"scripts": {
    "start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./node_modules/.bin/eslint **/*.js"

},

In which case the nodemon was not found.

So I changed the forward slashes to backslashes thus:

"scripts": {
    "start": ".\\node_modules\\nodemon\\bin\\nodemon.js src\\app.js --exec 'npm run lint && node'",
    "lint": ".\\node_modules\\.bin\\eslint **\\*.js"

},

but now when I run npm start I get an alert with error in nodemon.js

 line 1 
 charachter 1
 invalid character
 800A03F6

I tried with a forward slash in the src/app.js and got the same error. Is it something to do with the single quotemark?

The tutorial is here: (start command seen at 21:43) here: https://www.youtube.com/watch?v=Fa4cRMaTDUI&t=21m43s

Grieco answered 3/9, 2018 at 20:49 Comment(1)
this question is good for any app using nodemon: VUE, React, and the likes of those.Grieco
C
12

you just have to use

npx nodemon app.js command

after installing nodemon globaly with

npm install -g nodemon

Crawford answered 8/5, 2020 at 19:47 Comment(1)
When I run that on the command line, how come I keep spawning two node processes? It only does this when I launch my app via npm or npx. One just calls "node" referencing nodemon.js and my app.js as parameters, and then another calls node.exe with my original app.js path as it's parameterHeathcote
G
9

Solved!

OK, the solution was to install nodemon globally

npm i -g nodemon

And then changing the start string to

"start": "nodemon src/app.js --exec 'node && lint'"

Without it, running nodemon.js directly, even when I was inside the bin folder, was giving that error.

Nodemon version was and still is: 1.18.4 in both the local and global install.

Also, I had to change the single quotes in the --exec to escaped double quotes.

Instead of: "start": "nodemon src/app.js --exec 'npm run node && lint'"
I now have: "start": "nodemon src/app.js --exec \"npm run node && lint\""

The problem:

Calling the .js was the problem.

There is a nodemon.cmd command, in the users\<myuser>\AppData\Roaming\npm folder, which is in the windows 10 environment %PATH%.

There probably was a nodemon.cmd that I could call when installed locally. But don't ask me where that is.

Grieco answered 4/9, 2018 at 6:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.