I want to run more than one MEAN js 0.4.2 project using grunt.
First project is running properly by second project giving below error:-
[nodemon] starting `node --debug server.js`
Fatal error: Port 35729 is already in use by another process.
Warning: Use --force to continue.
change port in /config/env/default.js
port: process.env.PORT || 3002,
Please help.I have changed default port(/config/env/default.js) from 3000 to 3002 but still giving same error.
Issue is with the nodemon, two instances of nodemon tries to run on same port.
Try to run
node server.js
Or,
you can try to configure nodemon as well.
https://github.com/ChrisWren/grunt-nodemon/issues/21#issuecomment-28116032
Related
I attempted to use the command Heroku pg:psql to connect to my database addon in heroku but got a response below
--> Connecting to postgresql-regular-61345
unrecognized win32 error code: 123could not find a "psql" to execute
unrecognized win32 error code: 123could not find a "psql" to execute
psql: fatal: could not find own program executable
! psql exited with code 1
After using the heroku logs --tail command i got the following errors
sh: 1: nodemon: not found
Process exited with status 127
State changed from starting to crashed
I can also see all processes stopping with SIGTERM and the process exiting with status 143
Resolution steps I have taken
Verified that the environment variables have the path for installed postgress14 on my PC
Added a procfile to the root file in my backend code and spcified "web: node matthewfaceappback/server.js in the file"
Changed my set port to a variable port using process.env.PORT || 3000
Set all environment variable including my database url(set by default) on config variable in heroku
Verified there is a start up script
Updated all my packages using "npm update". after doing this i started expereincing the issue of processes stopping with SIGTERM and the process exiting with status 143
I moved nodemon from devDependencies to dependencies. nodemon version is 2.0.15
In package.json i inputed an engines parameter using the version of node in my case
{"engines": {
"node": "14.17.4"
}}
I restarted heroku using "heroku restart"
Below are links to the screenshots of the error
https://www.dropbox.com/s/5bdbyi9e99lbxhu/pic1.PNG?dl=0
https://www.dropbox.com/s/41euniaes5q68c9/pic2.PNG?dl=0
https://www.dropbox.com/s/50oqzbwmwrqogax/pic3.PNG?dl=0
Put nodemon back in the devDependencies and add it as a second node script in package.json:
"scripts": {
"start": "node matthewfaceappback/server.js",
"dev": "nodemon matthewfaceappback/server.js"
},
These two errors are completely unrelated.
The database connection error
The first issue, which I believe is the one you actually care about at the moment based on the title of the question, indicates that the Heroku CLI can't find a PostgreSQL client on your local machine.
The documentation makes the following recommendation
Set up Postgres on Windows
Install Postgres on Windows by using the Windows installer.
Remember to update your PATH environment variable to add the bin directory of your Postgres installation. The directory is similar to: C:\Program Files\PostgreSQL\<VERSION>\bin. Commands like heroku pg:psql depend on the PATH and do not work if the PATH is incorrect.
If you haven't already installed Postgres locally, do so. (This is a good idea anyway as you should be developing locally and you'll probably need a database.)
Then make sure to add its bin/ directory to your PATH environment variable.
The Nodemon error
The second issue is because you are trying to use nodemon in production. Heroku strips development dependencies out of Node.js applications after building them, which normally makes sense. Nodemon is a development tool, not something that should be used for production hosting.
Depending on the contents of your package.json, this might be as simple as changing your start script from nodemon some-script.js to node some-script.js. Alternatively, you can add a Procfile with the command you actually want to run on Heroku:
web: node some-script.js
See also Need help deploying a RESTful API created with MongoDB Atlas and Express
I'm attempting to start my react server through linux CLI with a specified port number. I am NOT asking about changing the package.json script to include a defined port number.
I need to be able to start multiple react instances with different ports through CLI.
I have seen recommendations such as
npm start --PORT=4000,
npm start --PORT 4000,
npm start -- --PORT=4000
Of which none work, they all set the port to the default of 3000, or if I have a defined port in the package.json such as 5000, it defaults to that.
Whats the correct command for setting the port through CLI?
you can do it by adding PORT=4000 before react-scripts start in package.json.
"scripts": {
"start": "PORT=4000 react-scripts start"
}
then you can execute npm start
It's actually an environment variable for the port, so you can specify a PORT environment variable beforenpm start
export PORT=3005; npm start #For Linux
$env:PORT=3005; npm start #For Powershell
I have a vue app created with the webpack-simple template.
I want to use an static port, so I hard code the port in the devServer property in the file webpack.config.js
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true,
port: 1123
},
The first time that I run npm run dev everything works fine. After I close the process with ctrl+c (using git bash in windows) and retry running npm run dev an error occurs telling me that the port is currently in use. If I change the port the first time it works then it repeats the same error (again and again).
I check the processs that is using the ports and it's node. I don't understand why node keep listening to those ports after I hit ctrl+c.
My dev script:
"dev": "cross-env NODE_ENV=development webpack-dev-server --hot"
Info
OS: Windows
Terminal: Git Bash
Node: v9.5.0
NPM: v5.6.0
Webpack: 3.6.0
Webpack-Dev-Server: 2.9.1
If the process exits abruptly, it doesn't close cleanly the listening server. The node process is terminated but the operating systems keeps the port open (in TIME_WAIT state) for a given amount of time to allow for the queues of packets to empty (see the socket FAQ and section "2.7 Please explain the TIME_WAIT state.".
In node, you can mitigate this problem by trying to close the server on exit and uncaughtException events. See this reply to a related question.
I create a simple node project using express:
npm install -g express-generator
express test
cd test/ && npm install
PORT=3000 npm start
So this gets the test app up and running on port 3000. Great. Now I'd like to use nodemon to run this project. I've installed it:
npm install -g nodemon
In the gihub README it is run the same way as node. This is a bit confusing, because the new way of starting node is npm start not node. So I tried:
$ PORT=3000 nodemon ./app.js
13 May 23:41:16 - [nodemon] v1.0.18
13 May 23:41:16 - [nodemon] to restart at any time, enter `rs`
13 May 23:41:16 - [nodemon] watching: *.*
13 May 23:41:16 - [nodemon] starting `node ./app.js`
13 May 23:41:16 - [nodemon] clean exit - waiting for changes before restart
But when I try to connect, there's nothing there. I confirmed that with:
lsof -i TCP:3000
Which returned nothing. Normally (with npm start) it returns:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 18746 user 10u IPv4 433546 0t0 TCP *:3000 (LISTEN)
Can anyone tell whats wrong here?
How is it possible to get the app to listen on the specified port with nodemon?
my setup:
npm -v
1.3.21
node -v
v0.10.24
nodemon -v
v1.0.18
express -V
4.2.0
in package.json
"scripts":{
// "start": "node ./bin/www"
"start": "nodemon ./bin/www"
}
the following would now be equivalent:
$ npm start
$ nodemon ./bin/www
This also works: Include this in your app.js (it does the same thing as the neolivz4ever said)
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + server.address().port);
});
you too use define your for nodemon:
$ nodemon --inspect ./bin/www 3000
If you are looking for the way to specify the port number with nodemon + express-generator, go to bin/www and change the line
var port = normalizePort(process.env.PORT || '3000');
to specific number. For example,
var port = normalizePort(process.env.PORT || '1234');
Additionally, some times, the port are just in use. If the other solutions not work for you, try change the port. It may be in use for some other node instance.
I use express-generator create the project skeleton, and use jade, sass instead of ejs and stylus, then i use concurrent to combine the watch and nodemon like the doc, but when i run grunt tasks, output is:
[nodemon] v1.0.17
[nodemon] to restart at any time, enter rs
[nodemon] watching: fir/*/*
[nodemon] starting node bin/www
Express server listening on port 3000
mongodb connection open
it's already use node to start server, How is it?
Yes.
Grunt, nodemon and Express allways are already to use NodeJS.
Nodemon, make easy cause you don't need allways, stop and start node to run your applications. If it don't work you can force reload using rs.