I need something like this:
nodemon.json:
[{
"watch": ["src/api-gateway"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/api-gateway/main.ts"
},
{
"watch": ["src/services/ping-service"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/services/ping-service/ping-service.ts"
}]
Is that possible, or if there is some alternative way to do it?
Use the array for watch option
"watch": [
"folder1",
"folder2",
]
You can look at the sample here https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md
Related
I'm trying to get test results and code coverage data after running jest tests. The resulting file contains the results of the tests, but no coverage data. I'm using jest-junit as my reporter. Here's what's in my package.json:
"scripts": {
"test": "jest --verbose --silent --coverage --coverageDirectory=./",
"start": "node server.js",
"dev": "nodemon server.js"
},
"jest": {
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"text",
"jest-junit"
],
"reporters": [
"default",
"jest-junit"
]
},
"jest-junit": {
"suiteName": "jest tests",
"outputDirectory": ".",
"outputName": "junit.xml",
"uniqueOutputName": "false",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
}
I have a Nodejs project which uses ESLint to keep consistency.
On my Mac machine, I have no troubles all works bur on Windows I got this error
No files matching the pattern "'./*'" were found.
Please check for typing mistakes in the pattern.
My setup for ESLint is
{
"env": {
"es6": true,
"node": true
},
"extends": [
"plugin:prettier/recommended",
"airbnb-base"
],
"plugins": [
"prettier"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"linebreak-style": "off"
}
}
Package.json
{
"name": "new-architecture-solution",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prod": "node -r esm server.js",
"dev": "nodemon -r esm server.js",
"debug": "ndb nodemon -r esm server.js",
"lint": "eslint . --ext .js,.jsx --quiet",
"fix": "eslint './*' --fix",
"prettier": "prettier --write src/**/*.{js,css}"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"eslintIgnore": [
"package.json",
"package-lock.json",
"combined.log",
"swagger.json",
"README.md"
],
"lint-staged": {
"./**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"npm run prettier",
"npm run lint --color",
"npm run fix",
"git add"
]
},
I'm unable to find asolution and I would like to have it work in both my machines
I haven't tried it yet on Windows, but according to this post replacing the single quotes with \" might do the trick. I've tried it on my Mac and it seems to work properly.
Edit: confirmed to work on Windows machines as well.
I use npm-run-all to run npm start and npm electron . and would like to enable debugging with VSCode, but not sure how to write the launch settings.
Currently, I have the settings below but get only
C:\Program Files\nodejs\npm.cmd dev --inspect-brk=32367
when I start the debugging.
How can I attach the debugger to the electron process?
package.json
{
...
"homepage" : "./",
"main": "src/main.js",
...
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron": "electron .",
"dev": "npm-run-all --parallel electron start"
},
...
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"env": {
"NODE_ENV": "development"
},
"windows": {
"runtimeExecutable": "npm"
},
"runtimeArgs": [
"dev"
]
}
]
}
I didn't add chrome debugger extension for VSCode.
It's now working with this settings, with run-script args.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"dev"
],
"port": 9229
},
]
}
Command tsc -w -p server watch the server directory compile TypeScript into dist/server folder (dist/server/app.js is the main Node script).
Command nodemon -w dist/server dist/server/app.js watches dist/server folder and reloads dist/server/app.js when something changes.
The problem: if I run both commands in parallel, tsc will take some times but nodemon starts too soon, when dist/server/app.js doesn't exist yet.
concurrently \"tsc -w -p server\" \"nodemon -w dist/server dist/server/app.js\"
On the other hand, if I run the commands sequentially I lost nodemon output (that is, the server output) because tsc will watch for changes and "steal" the console ouput:
tsc -w -p server\ && nodemon -w dist/server dist/server/app.js
I've tested both these strategies with nodemon and npm-run-all, a popular alternative.
Related questions (accepted answer doesn't solve the problem):
Is there a way to use npm scripts to run tsc -watch && nodemon --watch?
Adding a delay of 1000ms to nodemon fixed the issue for me.
https://github.com/remy/nodemon#delaying-restarting
nodemon.json
{
"watch": ["build"],
"ext": "js",
"exec": "npm start",
"delay": 1000
}
package.json
{
"name": "demo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node build/index.js",
"ts": "tsc -w",
"nodemon": "nodemon",
"code": "concurrently -n ts,nodemon npm:ts npm:nodemon"
},
"devDependencies": {
"concurrently": "^4.1.0",
"nodemon": "^1.18.9",
"typescript": "^3.2.2"
}
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "build",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
}
},
"include": [
"src/**/*"
]
}
npm run code
I am using babel-cli for jsx and es6 features to transpile
i have changed my build command
from
"build": "node build",
to
"build": "babel-node build",
Everything was working fine before
But when i run the build command i get this error
Error: locals[0] does not appear to be a module object with Hot Module replacement API enabled. You should disable react-transform-hmr in production by using env section in Babel configuration. See the example in README: https://github.com/gaearon/react-transform-hmr
See the screenshot also
So i should disable react-transform-hmr in production by using env section in Babel configuration
and this is my .babelrc like the instructions
{
"presets": ["react", "es2015"],
"env": {
"development": {
"plugins": [
["transform-object-rest-spread"],
["transform-react-display-name"],
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}]
}]
]
},
"production": {
"plugins": [
["transform-object-rest-spread"],
["transform-react-display-name"]
]
}
}
}
what am i doing wrong? Any recommendation?
I had to add NODE_ENV=production to the command
"build": "NODE_ENV=production babel-node build"