Error while watching folder and file for change - node.js

I am tailing a file for change and using fs.watch on a directory for newly added files and I received the following error causing my app to crash after a couple of hours working?
Any ideas what this means or why it would occur?
events.js:288
throw er; // Unhandled 'error' event
^
Error: ECONNRESET: connection reset by peer, watch
at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:127:28)
Emitted 'error' event on FSWatcher instance at:
at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:133:12) {
errno: -4077,
syscall: 'watch',
code: 'ECONNRESET',
filename: null

Related

How can I trace back "EPROTONOSUPPORT: protocol not supported :::3000" in node.js?

I am more than clueless at the moment. I am trying to start a keystonejs-6 app in production mode and the the app throws this error:
Starting Keystone
node:events:505
throw er; // Unhandled 'error' event
^
Error: listen EPROTONOSUPPORT: protocol not supported :::3000
at Server.setupListenHandle [as _listen2] (node:net:1355:21)
at listenInCluster (node:net:1420:12)
at doListen (node:net:1559:7)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1399:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EPROTONOSUPPORT',
errno: -43,
syscall: 'listen',
address: '::',
port: 3000
}
I have no way to trace back, at which point of the keystonejs application code the error originated. As it seems, keystonejs provides practically no logging on the application code itself.
Is there a way to find out, what kind of protocol is meant by this error message?

node:events:371 throw er; // Unhandled 'error' event ^ Error: read EFAULT

I've been getting this error and have tried reinstalling node/vscode already to no avail. This happens maybe 30% of the time after I save my changes in vscode and it ALWAYS crashes my node server.
Nodemon doesn't turn my server back on and it gets really tedious when trying to code. Does anyone have any solutions to this problem?
I'm running on a Macbook Air 2020 with a M1 chip if that makes a difference.
(Using express / nodejs ) node v16.6.0
I've tried killall node, I've tried changing port number. same errors
throw er; // Unhandled 'error' event
^
Error: read EFAULT
at Pipe.onStreamRead (node:internal/stream_base_commons:211:20)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -14,
code: 'EFAULT',
syscall: 'read'
}```

Unhandled 'error' event how to find out which line of code it's happening?

I'm getting this error:
events.js:137
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (_http_client.js:330:15)
at Socket.socketOnEnd (_http_client.js:423:23)
at Socket.emit (events.js:165:20)
at endReadableNT (_stream_readable.js:1101:12)
at process._tickCallback (internal/process/next_tick.js:152:19)
I know it's a socket.on('error') not handled, but the problem is I don't know where this socket is in my code. It doesn't say the line. Also this error only happens every 10min or so so I can't just comment things in and out and retry. Where can I know the exact line this socket is at?

Error: SQLITE_CANTOPEN: unable to open database file

I have nodejs repl and I am using SQLite. Somehow the SQList database file is giving me below error.
events.js:165
throw er; // Unhandled 'error' event
^
Error: SQLITE_CANTOPEN: unable to open database file
Emitted 'error' event at:
Here is the REPL.

Unhandled 'error' event in NodeJs

I'm working in NodeJs and when trying to write file as .pdf with the help of 'fs' npm package I got some error and even pdf is not generating. I need help to jump out of this, issue is
events.js:167
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at WriteWrap.afterWrite [as oncomplete] (net.js:833:14)
Emitted 'error' event at:
at onwriteError (_stream_writable.js:431:12)
at onwrite (_stream_writable.js:456:5)
at _destroy (internal/streams/destroy.js:40:7)
at Socket._destroy (net.js:603:3)
at Socket.destroy (internal/streams/destroy.js:32:8)
at WriteWrap.afterWrite [as oncomplete] (net.js:835:10)
Code regarding this error:
let doc = await wkhtmltopdf(options, xxxx);
let file = await doc.stdout.pipe(fs.createWriteStream(`${__dirname}/${id}_init.pdf`));
Thanks in anticipation!!
I have tried re-installing fs package, changing the ports but no improvement
I think the issue may be bcz of wkhtmltopdf package too(I'm using Mac)
I suggest you make the following changes, this is working very nicely for me:
// Set url and options to whatever you wish
let doc = wkhtmltopdf(url, options);
let file = doc.pipe(fs.createWriteStream(`${__dirname}/${id}_init.pdf`));
We can't use await on either call, since neither wkhtmltopdf nor doc.pipe return promises.
You can also try writing directly to file, skipping the stream, e.g.
wkhtmltopdf('http://google.com/', { output: 'out.pdf' });

Resources