In my package.json file I write this run nodemon:
"scripts": {
"test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
},
And this error showed in terminal:
> node-todo-api#1.0.0 test-watch D:\nodepractice\node-todo-api
> nodemon --exec 'npm test'
[nodemon] 1.12.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `'npm test'`
''npm' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
How to resolve this problem, I want to use nodemon.
Instead of putting in single quotes why don't you put in double quotes by escaping them.
Try this:
"test-watch":"nodemon --exec \"npm test\""
If you are working on Windows try to remove the single quotes after the exec command:
"test-watch": "nodemon --exec npm test"
Related
I got the source code from someone I know. But he uses Linux and I use Windows.
I used the following command to run this program.
"scripts": {
"dev": "nodemon --watch src --watch package.json --watch tsconfig.js --delay 1 --exec 'cross-env HTTP_PORT=4080 NODE_ENV=develop ts-node' src/index.ts",
"lint": "tslint -p .",
"build": "tsc",
"dto:build": "tsc src/dto/*.ts --declaration --emitDeclarationOnly --experimentalDecorators --outDir dto",
"dto:publish": "rm -rf dto; npm run dto:build && cp package.dto.json dto/package.json && cd dto && npm publish --access public"
},
npm run dev
When I run this script, I got the following result.
[nodemon] 2.0.13
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): src\**\* package.json tsconfig.js
[nodemon] watching extensions: ts,json
[nodemon] starting `'cross-env HTTP_PORT=4080 NODE_ENV=develop ts-node' src/index.ts`
''cross-env'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는
배치 파일이 아닙니다.
[nodemon] app crashed - waiting for file changes before starting...
''cross-env'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는
배치 파일이 아닙니다.
<< this mean 'cross-env' is not recognized as an internal or external command (maybe)
As a result I don't know how to solve this.
I also installed cross-env using npm install.
I expect this to be a different command for Linux and Windows.
I would appreciate it if you could tell me the cause of this and how to fix it.
I'll attach a rough file structure.
I have installed the bable-cli and the babel-preset-env, after installing nodemon the npm start fail to load my application when using the following in the package.json file:
"scripts": {
"start": "nodemon src/index.js --exec babel-node"
}
Showing the following error:
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node src/index.js`
'"node"' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
But everything works fine when using the following:
"scripts": {
"start": "babel-node src/index.js"
}
Thanks!
I ran into the same problem and solved it this way:
"scripts": {
"start": "babel-node src/index.js"
"dev" : "nodemon --exec npm start"
}
The reason is because you are not sending anything to babel to transpire and run. nodemon just looks for file changes.
Try this instead.
"serve":nodemon --exec babel-node src/index.js
If that doesn't work make sure you have the proper DEV dependencies.
#babel/core
#babel/node
#babel/cli
#babel/preset-env
configure .babelrc to have the following
{
"presets" : ["#babel/preset-env"]
}
I setup some scripts in package.json as follows:
"scripts": {
"dev:server": "nodemon --watch build --exec \"node build/bundle.js\"",
"dev:build:server": "webpack --config webpack.server.js --watch"
},
but I get the following error when I run npm run dev:server
[nodemon] 1.12.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: C:\Users\adinu\Documents\Dev\React Training Code\Udemy\Code\server\build/**/*
[nodemon] starting `node build/bundle.js`
'\"node build\bundle.js\"' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
If I run node build/bundle.js directly from the terminal, I get no errors.
I also checked the standard things like making sure nodejs is in the path, re-started the machine etc.
Thanks
Alex
To make sure it works in windows, use the script as follows: remove the \" ... \" code around.
"scripts": {
"dev:server": "nodemon --watch build --exec node build/bundle.js",
"dev:build:server": "webpack --config webpack.server.js --watch"
},
On MacOS Catalina, your code worked fine. I suggest removing the \" around node build\bundle.js, so your script looks like this:
"dev:build:server": "webpack --config webpack.server.js --watch"
That also worked for me.
I have a simple node server written in typescript. My package.json is configured as:
"scripts": {
"build": "tsc",
"dev": "nodemon --watch src/**/* -e ts,json --exec ts-node ./src/server.ts",
"debug": "nodemon --verbose --watch src/**/* -e ts,json --exec ts-node --inspect ./src/server.ts"
},
When I run npm run dev nodemon will launch the server and restart it when any changes are made.
[02/28/18 20:45:53] npm run dev
> pq-api#1.0.0 dev C:\Users\joe\pq\pq-api
> nodemon --watch src/**/* -e ts,json --exec ts-node ./src/server.ts
[nodemon] 1.15.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: src/**/*
[nodemon] starting `ts-node ./src/server.ts`
initializing config to development
info: PQ-API running on port 3000
However, when I run npm run debug (so I can attach a debugger) It looks like it begins to start, but just hangs forever
[02/28/18 20:39:30] npm run debug
> pq-api#1.0.0 debug C:\Users\joe\pq\pq-api
> nodemon --verbose --watch src/**/* -e ts,json --exec ts-node --inspect ./src/server.ts
[nodemon] 1.15.1
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 10156 to restart
[nodemon] watching: src/**/*
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node --inspect ./src/server.ts`
[nodemon] spawning
[nodemon] child pid: 13344
[nodemon] watching 12 files
That is all the output has. The script is never executed; the server never starts up, and the inspector is never available to connect to.
node 8.94
nodemon 1.15.1
ts-node 5.0.0
typescript 2.7.2
With ts-node 5.0.0 you no longer pass the --inspect flag the same way. The suggested way is node --inspect -r ts-node/register path/to/ts. For example:
nodemon --watch src/**/* -e ts,json --exec node --inspect-brk -r ts-node/register src/app.ts
see https://github.com/TypeStrong/ts-node/issues/537
Provide location and port to the inspect option like:
--inspect=0.0.0.0:9200
I am using PHP Storm and the previous answer of #user60456 works like a charm for me.
With some changes, I was able to run debug mode using dotenv with multiple env files in PHP Storm as well.
package.json
"start:dev": "nodemon --watch src/**/* -e ts,json --exec node --inspect-brk -r ts-node/register -r dotenv/config local.ts dotenv_config_path=./.env.development",
where local.ts is the file where my app.listen() is.
Then, I had to create a new Run configuration (Attach to Node.js/Chrome) with:
host: localhost
port: 9229
Attach to: Chrome or Node.js > 6.3 started with --inspect
Then select the root folder in Remote URLs of local files tab and set the Remote URL to /usr/src/app.
Now, you can run npm run start:dev. You will see the console output:
Debugger listening on ws://127.0.0.1:9229/...
You have to run the Nodej.js debug configuration now and wait, until you see the console output:
Debugger attached.
The application is now running in debug mode.
I made changes using some of the info above as mine just didn't seem to work and the change I made did resolve the problem.
From "start": "tsnd --inspect -- src/app.local.ts"
To: "start": "node --inspect -r ts-node/register src/app.local.ts"
I just fixed this problem by writing nodemon.json file like this :
{
"restartable": "rs",
"ignore": [".git", "node_modules/**/node_modules"],
"verbose": true,
"execMap": { // [A]
"ts": "node --require ts-node/register"
},
"watch": ["src/"],
"env": {
"NODE_ENV": "development"
},
"ext": "js,json,ts"
}
ref : https://dev.to/oieduardorabelo/nodejs-with-typescript-debug-inside-vscode-and-nodemon-23o7
I had a different issue resulting in the debugger never running. I was running this command,
node index.js --inspect=5005
instead of this,
node --inspect=5005 index.js
The flag is supposed to be before the source file.
I'd like to get my package.json to be able to run using the command npm run test-watch on Windows 10 with npm 5.5.1. In my package.json:
"scripts": {
"test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
}
However, I this interpretes the code strangely to have a single quote in there. I'm actually following a Udemy course so it appears to work for the instructor. However, here is the output I get:
PS D:\courses\node-course\node-todo-api> npm run test-watch
> todo-api#1.0.0 test-watch D:\courses\node-course\node-todo-api
> nodemon --exec 'npm test'
[nodemon] 1.14.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `'npm test'`
''npm' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
What do I need to change to get this to work? It appears to be keeping the quotes on the string. I can't seem to get around it though. When I run the command directly, it works:
PS D:\courses\node-course\node-todo-api> nodemon --exec 'npm test'
[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `npm test`
> todo-api#1.0.0 test D:\courses\node-course\node-todo-api
> mocha server/**/*.test.js
started on port 3000
Post /todos
√ should create a new todo (50ms)
1 passing (1s)
Unfortunately, the operating system and shell can cause a massive headache when using npm. Some things work on one computer and some on another.
Both of these should work on Windows 10 though:
"test-watch": "nodemon --exec \"npm test\""
"test-watch": "nodemon --exec npm test"