Change to STDOUT logging on nodejs app - node.js

Following on from this:
ENOENT error using nodejs on heroku
I've been suggested to use STDOUT logging on my node.js app...?
Is this possible?
If so, how / where do I configure this?

Related to:
ENOENT error using nodejs on heroku
I ended up disabling 'quiet' mode to stop writing logs to disk:
app.disable('quiet');
This seems to of resolved it

Related

Make nodemon auto-restart a program on crash without waiting for file changes at custom error?

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.

'heroku local' cannot find module 'load-foreman-procfile'

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.

node app on aws elastic beanstalk; Node Command setting results in command not found

I'm trying to start my application with a different file; not app.js or server.js, and I don't want to add a start script to npm as there's several possible configurations for this application. In the elastic beanstalk console, under Configuration -> Software Configuration, there's a Node command setting, and I'm setting the value to the file I want, like:
eb_server.js
and also tried node eb_server.js
But in the nodejs logs on the app server (/var/log/nodejs/nodejs.log, I get this output:
sh: eb_server.js: command not found
My question is what's the proper way to set the alternative start script command using the elastic beanstalk console?
Turns out it's not meant for a node command directly, but rather an npm command. You can specify "npm run ", where you can call the custom node start command, pointing to whatever file you want. Naming is hard... ;-)

Debugging nodejs while using Kinesis MultiLangDaemon/KCL

Following this post I was able to connect our existing nodejs code into Kinesis logs (using KCL and MultiLangDaemon).
The problem is that I can't debug the code anymore.
Since MultiLangDaemon uses STDIN/STDOUT to interact with executed "script", once I call "node --debug" and get the message:
"debugger listening on port 57846"
I get an error from the MultiLangDaemon saying:
"SEVERE: Received error line from subprocess [debugger listening on port 57846] for shard shardId-000000000000"
Is there a way to execute nodejs "quietly", so it won't send this STDERR message ?
Does anyone have experience with MultiLangDaemon and debugging ?
Thanks,
Shushu
I got an answer in here, recommending to work with node inspector.
After installing, all I had to do is to change the kinesis.properties executableName from "node" to "node-debug", and I got it working.

ENOENT error using nodejs on heroku

I'm getting an ENOENT error on my heroku app, preventing it from starting up:
Error: ENOENT, open '/app/log/production.log'
This file / dir (app/log) does exist however...
So I'm not sure what's going on?
I ended up disabling 'quiet' mode to stop writing logs to disk:
app.disable('quiet');
This seems to of resolved it

Resources