According to the documentation, ignoring the Data.json file requires this command to be executed:
nodemon --ignore Data.json
I tried exactly that and it didn't work. The console kust returned:
Usage: nodemon [nodemon options] [scripts.js] [args]
See "nodemon --help" for more.
Other commands i tried:
nodemon --ignore 'Data.json'
nodemon --ignore "Data.json"
nodemon --ignore '/Data.json'
nodemon --ignore /Data.json
You need to pass your Server.js to nodemon prior to the ignore
nodemon Server.js --ignore 'Data.json'
Alternatively you can create a nodemon.json file
{
"verbose": true,
"ignore": ["Data.json"]
}
and then pass this as a commandline argument
nodemon Server.js --config nodemon.json
Related
Previously, I was starting a nodejs sever with:
"start": "node --max-old-space-size=1024 index.js",
But now it was migrated to typescript, and some change the start script to:
"start:ts": "nodemon server.ts",
But with that I'm losing the option --max-old-space-size=1024.
How can I start the server using nodemon but with --max-old-space-size=1024 ?
I tried:
"start:ts": "nodemon --max-old-space-size=1024 server.ts",
but says:
[nodemon] starting `ts-node --max-old-space-size=1024 server.ts` /MyProject//node_modules/arg/index.js:90
throw err;
^
Error: Unknown or unexpected option: --max-old-space-size
I just discovered it's quite complicated to pass arguments to Node using ts-node. As per the docs, you can call Node and register ts-node in the command. You can use the --exec flag on nodemon to execute a custom command. Here's how I would frame the entire command:
nodemon --exec "node --max-old-space-size=1024 -r ts-node/register ./server.ts"
You can alternatively call ts-node directly and specify the NODE_OPTIONS environment variable:
nodemon --exec "NODE_OPTIONS='--max-old-space-size=1024' ts-node ./server.ts"
I have this script in my package.json
"watch": "nodemon --watch components --watch helpers --watch redux --watch services --watch types --watch views --watch assets -e ts,scss,css --exec \"npm run build:localhost\"",
So my nodemon is watching my local folders, I just save a single file and this many processes are created.
I use this script to call my webpack build command upon saving a file. This webpack command builds a dist which is the server by a local nginx to localhost.
Is there a way to go over the problem?
Mocha does not find the path to .mocharc.js file with the config.
The file is located at: app/test/.mocharc.js
I have tried setting relative as well as full paths and it always throws an error. Used quotation marks, double quotations, escaped quotations... Still I get the same error.
In package.json:
"scripts":{
test": "nodemon --exec \"mocha --config \"./test/.mocharc.js\""
},
Command line Error log:
throw new Error(`failed to parse ${filepath}: ${err}`);
^
Error: failed to parse ./test/.mocharc.js: Error: Cannot find module './test/.mocharc.js'
Your test script command is in incorrect format (unnecessary double quote).
"scripts":{
test": "nodemon --exec \"mocha --config ./test/.mocharc.js\""
},
You want to run mocha --config ./test/.mocharc.js.
And to wrap that into nodemon, you do:
nodemon --exec \"<command here>\"
Replace <command here> with your command like so.
nodemon --exec \"mocha --config ./test/.mocharc.js\"
This is my nodemon.json
{
"watch": ["src/**/*.ts"],
"exec": "node out/index.js"
}
I run the nodemon by executing:
nodemon
In root nodejs directory
This is output:
% nodemon
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: src/**/*.ts
[nodemon] starting node out/index.js
Yay! Started app!
But when I edit any ts file in src nodemon doesn't restart the app.
UPDATE
Running nodemon --watch src/index.ts --exec 'node out/index.js'
Works and reloads the app on modifying index.ts
However, running with wildcard
nodemon --watch 'src/**/*.ts' --exec 'node out/index.js'
or
nodemon --watch src --exec 'node out/index.js'
Doesn't reload the app.
Solved!
By running nodemon in verbose mode I have discovered that by default it watches only *.js files, regardless of what wildcard you are watching. Therefore adding -e ts to the command fixes the problem:
nodemon --watch src/ --exec 'node out/index.js' -e ts
If someone uses nodemon.json here is mine after fix:
{
"watch": ["src"],
"exec": "tsc && node out/index.js" ,
"ext": "js, json, ts, proto"
}
I didn't have any luck with src/ watching either. I'm watching files via nodemon --watch '**/*' this will finds any changes in the nested files
Use single quotation for multi-value args like `--exec' in the package.json script.
e.g. I changed "nodemon --exec npm run build-langs" to "nodemon --exec 'npm run build-langs'" and worked.
I install the nodemon for my node project.
And I use "--watch app" command to watch the file change.
When I modify other files, it works well, I can see the auto restart log on the screen ( Windows powershell ).
However, when I modify the template engine file (path: app/view/index.nj), they do not restart automaticlly.
How to resolve this problem?
Here is a part of "package.json" file
"scripts": {
"dev": "nodemon --watch app --ignore app/static/css --ignore app/static/js ./dev.js"
}
Nodemon only restarts if .js and .coffee files are changed by default. You have to pass the extension to the nodemon.
"scripts": {
"dev": "nodemon -e js,html,nj --watch app --ignore app/static/css --ignore app/static/js ./dev.js"
}