I cloned this repo from gitHub so, while installing in the last step I try to run this command:
~/mqtt-gateway$ WEB_API_URL=http://localhost:3000 npm start
And I get this error:
[nodemon] app crashed - waiting for file changes before starting...
I've read that possibly is because of a process that haven't been terminated but I've been unable to solve it.
Hope you can help. Thank you ;)
i had that issue myself, when i was building a server .. on command npm run dev:server, it was always rejecting me with that message "[nodemon] app crashed - waiting for file changes before starting"
my package.json was:
"scripts": {
"dev:server": "nodemon --watch build --exec node \"build/bundle.js\"",
"dev:build:server": "webpack --config webpack.server.js --watch"
},
so i just removed those escaping backslashes and everything worked fine.
"scripts": {
"dev:server": "nodemon --watch build --exec node build/bundle.js",
"dev:build:server": "webpack --config webpack.server.js --watch"
}
In the error output it said:
Error: listen EADDRINUSE :::1883
The port used for this program is 1883 and I was running mosquitto on that same port so I killed it:
netstat -plten |grep mosquitto
and then
kill -9 PID
like in this question.
Just in case anyone faces a similar problem.
Related
I use nodemon to run a node.js app during development. When I save a file in the project the app restarts.
The problem is sometime the previous process on that post does not allow the app to restart.
My start script in my package.json looks like this:
"scripts": {
"start": "nodemon app.js",
"test": .....
},
When that happens I run this in terminal:
kill -9 $(lsof -t -i:4080)
Then the app works fine again.
How do I force nodemon to not try to restart until the previous process stopped and the ports is available again?
You can create an npm script that runs the kill process:
"dev": "kill -9 $(lsof -t -i:4080) && node app.js",
"start": "nodemon --exec npm run dev"
Notice in how your nodemon script you're running another script with --exec.
Start the server like you usually would:
npm start
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"
}
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 downloaded the zip (from https://github.com/artf/grapesjs) and unzipped, then did the "npm i" command. That tooks a while, then I ran "npm start" and the console displayed this:
e:\GitHub\NealWalters\GrapeJSDemo>npm start
grapesjs#0.14.5 start e:\GitHub\NealWalters\GrapeJSDemo
npm run build:css -- -w & webpack-dev-server --open --progress --colors
grapesjs#0.14.5 build:css e:\GitHub\NealWalters\GrapeJSDemo
node-sass src/styles/scss/main.scss dist/css/grapes.min.css --output-style compressed "-w"
When I try http://localhost:8080 in the browser, I get the error:
This site can’t be reached
localhost refused to connect.
Here is my directory structure:
I have run other NodeJS programs before with success. Running on Windows 10.
On npm start, the process gets bound to watching files and doesn't reach the next command to startup the server. Try adding start in the beginning of the start script to run a separate process for watching the files. Then the command to startup the server will get executed.
So in package.json, change the start script to the following:
{
...
"scripts": {
...
"start": "start npm run build:css -- -w & webpack-dev-server --open --progress --colors"
}