15:05:09 web.1 | started with pid 4888
15:05:10 web.1 |
15:05:10 web.1 | > finext_server#0.0.1 test F:\Projects\finext\server
15:05:10 web.1 | > set NODE_ENV=development && node ./bin/www.js
15:05:11 web.1 |
15:05:12 web.1 | exited with code 5
15:05:12 system | sending SIGKILL to all processes
15:05:12 | app.get('env'): development
This is the output I get, and it is a little variable in terms of the code that gets executed after SIGKILL. Sometimes, a few more lines of coide get executed before I see the command prompt again.
I tried using node-foreman, and my application works fine there. So i am guessing it has something to do with foreman. My code and procfile can be found here: https://github.com/chintanp/finext
This is the reason that the process cannot start on heroku as well.
Someone in another world had a similar problem. Express Hello World -- Heroku Foreman Returns Code 5, 'npm start' works just fine
In Procfile try this:
web: node app.js
I recently faced exactly the same situation as you when running my application:
foreman logged the messages "exited with code 5" and "sending SIGKILL to all processes".
My app worked fine if I used npm ("npm start") or node-foreman ("nf start") instead of foreman.
The app also worked using forego, a go application written by the author of foreman.
But a couple of weeks ago heroku added the new command "heroku local", which uses forego behind the scenes, and formally supersedes the use of foreman:
Starting today, new Heroku Toolbelt installs will not come with
Foreman. The command heroku local has replaced foreman. Heroku Local
makes use of Forego to accomplish its tasks and it’s faster and has
better cross-platform support.
Note that heroku also now state that foreman is "not officially supported".
So the way to resolve your problem is:
Stop using foreman.
Download and install the latest version of heroku toolbelt.
Replace "foreman start" with "heroku local".
This approach worked for me on Windows 7.
Related
After upgrading to node version 16.13.0, server will occasionally crash locally. In this react/node.js/mssql app I am working on, nodemon will sometimes crash the node server out of nowhere with no error message. Is there someway to debug this? If I save a file/restart the node server, it will spin up again and work for approx. 2 mins before crashing again.
command used to run the server:
cross-env NODE_ENV=local DEBUG=express:* nodemon -e js,mjs,coffee,litcoffee,json,sql ./server/server.js
I'm building an E-commerce site, where there's an Authentication system.
I noticed that if the client login with a wrong user or password, the backend/server that works with nodemon will crach and hang in there crashed till i restart manually nodemon. This is example output error of the nodemon crash:
[nodemon] app crashed - waiting for file changes before starting...
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent
to the client
Ofcourse, when server crashes, client can no more access or do login again till server restarts.
After some googling, i found this question and this repository that fix my problem but particulary and not as expected precisely, i dont want nodemon to restart forever on any error that occure ofcourse, but only with specifics errors that i set them -like Authentication errors as i mentionned above-.
So, my idea/question is: is there anyway to get nodemon restarts by itself in some cases of failures or errors (NOT ALL)?
Seems like you a referring to a production situation, and nodemon is a development node server, which is not intended for use in production, as the intro states:
nodemon is a tool that helps develop Node.js based applications by
automatically restarting the node application when file changes in the
directory are detected.
You should use node.js in production, instead of nodemon.
For managing your node server in production, you could use a process manager like PM2..
That said, an authentication server that crashes every time a user uses a wrong password seams very ineffective in handling a common use case. So I would advise to start with fixing the root cause, which is the buggy server, and then for recovery from incidental crashes use something like PM2.
PS:
The error you are getting looks like an express error you get when you send a response (in this case an error response) without exiting the function e.g. by using return. Because you are not returning, another res.send is called, which causes the 'ERR_HTTP_HEADERS_SENT' error. See this answer.
This is really bad since it can send your program into a loop of restarting, but if you really want it, replace app.js with your file's name and try this:
nodemon -x 'node app.js || copy /b app.js +,,'
Linux version:
nodemon -x 'node app.js || touch app.js'
Next time try a little googleing before you ask since it is most likely faster.
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 trying to run Heroku applications locally via 'heroku local,' but a missing module error is occurring in the Heroku CLI. Is this a Heroku bug that just needs to be reported or is there something wrong with how things have been setup on my machine (mac)? Any suggestions are appreciated.
In order to ensure my application isn't the problem, I've been debugging this issue with the node application Heroku provides in its getting started guides. Meaning, it already has a Procfile that can be run using default settings.
Things I've tried:
Re-install node modules for both application and CLI
Re-install the Heroku CLI
Here's the error:
node-js-getting-started [master] :> heroku local
Error: Cannot find module '../../load-foreman-procfile'
at Object.<anonymous> (/usr/local/Cellar/heroku/7.26.1/libexec/node_modules/#heroku-cli/plugin-local/lib/commands/local/index.js:5:18)
The file for the route above requires a 'load-foreman-procfile' like so:
const Procfile = require('../../load-foreman-procfile');
That require path doesn't lead to a to file by that name. In fact, this is the only reference to 'load-foreman-procfile' I can find in '/usr/local/Cellar/heroku/7.26.1'.
Rather than the error code above, I would expect heroku local to yield a running local server started via my Procfile.
I got the same error running heroku-cli v7.26.0. I switched to their edge channel (currently v7.26.2) and heroku local worked for me after that.
like #sophon mentioned - updating from v7.26.0 to v7.26.2 solved this for me. heroku update on mac did the trick.
I want users to submit code and run tests against that code using AVA. The AVA CLI seems great. But this would be running in a hosted environment like Heroku and need to respond back to the POST request containing the code submission with the results of the unit tests.
When I try var test = require('ava') and then call the test function in a route, I get this message when starting the node server:
[OKAY] Loaded ENV .env File as KEY=VALUE Format
10:24:11 PM web.1 | Test files must be run with the AVA CLI:
10:24:11 PM web.1 | $ ava index.js
[DONE] Killing all processes with signal null
10:24:11 PM web.1 Exited with exit code 1
I think it is not possible, it is thought to be used through the cli. Actually to me it does not make much sense for it be used as a required module in your code.
How did you plan to use it? If you just want to use the assertions you can use some assertion library like chai, expect or power-assert.
If you want more information opening an issue in the AVA repo also could be an option.