Setting Path for Mocha with --config - node.js

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\"

Related

Start nodemon with --max-old-space-size

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"

how to use nodemon to inherit from another script

I have a script that runs a nodejs app
package.json:
{
"scripts": {
"start": "node app.js --inspect --other-flags ....",
"start:inspect": "npm run start -- --inspect",
"start:watch": "nodemon app.js ..."
}
}
as you can see in the script "start:inspect" in inherit all flags from "start" and adds "--inspect"
I want to inherit all "start" flags into "start:watch" but with nodemon without manual copying
something like "start:watch": "npm run start -- nodemon"
You could do this with an environment variable for the command, like "start:watch": "export CMD=nodemon; npm run start" and "start": "$CMD app.js ..."

Typescript package.json scripts run build and start concurrently: port already in use

I am having an interesting problem building my typescript server using nodemon. I have a script for building out the ts files, and then starting the server. However, when I run these two concurrently, it starts at first fine, then after it is done building, it restarts, but gives me an error that the port is already in use. Is there a way to somehow kill the port each time before it starts?
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "nodemon dist/index.js",
"build:dev": "tsc --watch --preserveWatchOutput",
"dev": "concurrently \"npm:build:dev\" \"npm:start:dev\""
},
I have tried adding "npx kill-port 8080 && nodemon dist/index.js" to the start:dev, but I am still getting that error. I have also tried "npx kill-port 8080; nodemon dist/index.js" Is there a solution to this issue? Thanks.
Edit: It seems that this is actually working as I expected it too however, for some reason the terminal is still showing an error message and therefore, anything my server logs to the console is hidden. Is there any way to fix this? Thanks.
I am not sure why exactly you get a port error, but you can improve your setup. Nodemon can run typescript with ts-node help.
Just install ts-node and run nodemon with --exec 'ts-node' property.
Example from my package.json:
{
"dev": "nodemon --watch 'src/**/*' -e 'ts' --exec 'ts-node' src/index.ts"
}

nodemon --ignore not recognized

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

IntelliJ IDEA: How can I create an breakpoint that debug webpack?

Use Intellij IDEA's debug tool to webpack,
OS:MAC
npm script:
"scripts": {
"dev": " webpack-dev-server --inline --hot --display-error-details --content-base --config mvvm/build/webpack.dev.conf.js",
}
it tips:
To debug "build-distributor" script, make sure $NODE_DEBUG_OPTION string is specified as the first argument for node command you'd like to debug.
For example:
{ "start": "node $NODE_DEBUG_OPTION server.js" }
question:
Where to add this code($NODE_DEBUG_OPTION )?
Package.json configuration
First of all you have to create a new Debugging script like this:
"debug": "node $NODE_DEBUG_OPTION node_modules/.bin/webpack-dev-server --config ./path/to/webpack.config.js"
webpack configuration
You have to add this command line:
devtool: 'eval-source-map'
Editor configuration
and then you have to cofigurate your IDE:
and also this:

Resources