Node.js stdout flush - node.js

Maybe I'm duplicating this question, but the answer provided refers probably to an older version of node (i'm using v0.5.10), because fs.writeSync(1, "Foo\n"); alone doesn't solve my problem (the output doesn't get flushed when executing the script from a shell script) and fs.fsyncSync(1); is not documented and when I try it node rises the exception:
return binding.fsync(fd);
^
Error: UNKNOWN, Operation complete;
at Object.fsyncSync (fs.js:353:18)
at Interface.<anonymous> (C:\Dev\Git\org.github.pistacchio.streamcommunication\nodebot.js:36:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
at ReadStream.<anonymous> (readline.js:82:12)
at ReadStream.emit (events.js:88:20)
at ReadStream._emitKey (tty.js:309:10)
at ReadStream.onData (tty.js:66:12)

You want it to be blocking, but I guess streamlinejs should work for you, too:
var done = process.stdout.write(str);
if (!done) {
// this effectively means "wait for this
// event to fire", but it doesn't block everything
process.stdout.on('drain', _)
}
doSome(otherStuff)
You can paste this code here to see what it will be compiled to when you call it. Also, you'll have to install streamline with npm install streamline -g, to put your code in a file which has a name ending with _.js and to run your code with node-streamline filename_.

Related

What's "EIO: i/o error, write" in node.js and how do I eliminate it?

I have a node.js app using elasticsearch to gather error data and notify relevant stack holders. It starts to give me errors lately (no change has made to the code):
write EIO
Error: write EIO
at afterWriteDispatched (internal/stream_base_commons.js:154:25)
at writeGeneric (internal/stream_base_commons.js:145:3)
at WriteStream.Socket._writeGeneric (net.js:783:11)
at WriteStream.Socket._write (net.js:795:8)
at doWrite (_stream_writable.js:385:12)
at writeOrBuffer (_stream_writable.js:367:5)
at WriteStream.Writable.write (_stream_writable.js:307:12)
at Stdio.write (/project/node_modules/elasticsearch/src/lib/loggers/stdio.js:58:6)
at Stdio.onError (/project/node_modules/elasticsearch/src/lib/loggers/stdio.js:70:8)
at Log.wrapper (/project/node_modules/lodash/lodash.js:4929:19)
at Log.emit (events.js:315:20)
at Log.error (/project/node_modules/elasticsearch/src/lib/log.js:239:17)
at checkRespForFailure (/project/node_modules/elasticsearch/src/lib/transport.js:298:18)
at HttpConnector.<anonymous> (/project/node_modules/elasticsearch/src/lib/connectors/http.js:171:7)
at ClientRequest.wrapper (/project/node_modules/lodash/lodash.js:4929:19)
at ClientRequest.emit (events.js:315:20)
I suspect this has to do with some type of I/O error on the disk. What can I do to eliminate the error? I am using Node.js v14.0.0 and elasticsearch (npm package) 16.7.1.
This can be caused by multiple reasons:
If you are using Windows is most likely a unicode issue you can fix by executing chp command like this chcp 850 but if you need Unicode characters then iconv-lite module should help
When trying to write to a closed terminal
Disk related issues, like the disk is full or OS issues... when trying to write the output
Try to reinstall the modules to the latest version and from scratch since maybe you are using a buggy module or it wasn't installed correctly
This turns out to be a bug in ElasticSearch's log feature due to the fact it is writing to the stdio synchronously. We will either have to turn off the log or use a third party logger.

Jasmine test suite doesn't run

I can't figure out what I've done to mess up Jasmine.
Here's a link to the repo I'm working on:
https://github.com/bryanbeus/04-09-bloccit/tree/v0.1.3
The problem is somehow related to the files /spec/integration/flairs_spec.js, /spec/integration/post_spec.js, and probably more.
The problem can be seen when running a command like npm test. I get the following result:
04-09-bloccit#1.0.0 test /home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit
export NODE_ENV=test && jasmine
npm ERR! Test failed. See above for more details.
It used to be that this ERR would only occur if I had an non-compilable error somewhere in my code. (For example, a simple thing like ; out of place, or an improper use of this.)
Recently, I've heard from someone else that this type of failure for Jasmine isn't normal. Usually, if there's a problem in the code, Jasmine is still supposed to say something. ?
Whatever the problem is, it is now spreading to general usage.
I'm trying to call the server npm module for a test with this command:
const server = require("../../src/server");
If that line is anywhere in my files, the entire Jasmine test fails in the exact same manner. (npm ERR... and no other details.)
If I run npm test /spec/integration/flairs_spec.js with that call to server active, the test fails in the npm ERR... manner.
However, if I comment out the call to server, then Jasmine at least runs. It returns this error:
....................
Started
F
Failures:
1) routes : flairs GET /topics/:topicId/posts/:postId/flairs/new should render a new flair form
Message:
Expected Error: connect ECONNREFUSED 127.0.0.1:3000 to be null.
Stack:
Error: Expected Error: connect ECONNREFUSED 127.0.0.1:3000 to be null.
at
at Request.request.get [as _callback] (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/spec/integration/flairs_spec.js:57:21)
at self.callback (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:186:22)
at Request.emit (events.js:160:13)
at Request.onRequestError (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:878:8)
at ClientRequest.emit (events.js:160:13)
at Socket.socketErrorListener (_http_client.js:389:9)
at Socket.emit (events.js:160:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
Message:
Expected undefined to contain 'New Flair'.
Stack:
Error: Expected undefined to contain 'New Flair'.
at
at Request.request.get [as _callback] (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/spec/integration/flairs_spec.js:58:22)
at self.callback (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:186:22)
at Request.emit (events.js:160:13)
at Request.onRequestError (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:878:8)
at ClientRequest.emit (events.js:160:13)
at Socket.socketErrorListener (_http_client.js:389:9)
at Socket.emit (events.js:160:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
1 spec, 1 failure
Finished in 0.399 seconds
npm ERR! Test failed. See above for more details.
.......
So, removing the server call at least lets Jasmine run.
Any help on this is appreciated. Thank you for helping a novice programmer.
I found the source of the error.
Using git diff v0.1.2..v0.1.3 I was able to see the differences between the last working branch, and the current one.
From here, I saw that in db/src/controllers/flairController.js I had placed this in the controller for the flair object:
const flairQueries = require("./db/queries.flairs.js");
The problem with that is that the directory isn't correct. I replaced it with this:
const flairQueries = require("../db/queries.flairs.js");
After this, the Jasmine test suite worked.
I understand that this means that the controller couldn't load properly. The full understanding of this is still elusive, so if anyone has time to try to explain, I would appreciate it. Otherwise, we can consider this question closed. Thanks!

Error: ENOENT, no such file or directory 'data.json' when running `jsonplaceholder`

When I run jsonplaceholder I get:
jsonplaceholder
JSONPlaceholder listening on http://localhost:3000
fs.js:432
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT, no such file or directory 'data.json'
at Object.fs.openSync (fs.js:432:18)
at Object.fs.readFileSync (fs.js:286:15)
at Object.index.load (/usr/local/lib/node_modules/jsonplaceholder/node_modules/json-server/node_modules/lowdb/node_modules/underscore.db/src/node.js:11:24)
at Function.low.load (/usr/local/lib/node_modules/jsonplaceholder/node_modules/json-server/node_modules/lowdb/lib/index.js:110:29)
at reset (/usr/local/lib/node_modules/jsonplaceholder/index.js:6:14)
at Server.<anonymous> (/usr/local/lib/node_modules/jsonplaceholder/index.js:14:3)
at Server.g (events.js:180:16)
at Server.EventEmitter.emit (events.js:92:17)
at net.js:1052:10
at process._tickCallback (node.js:415:13)
Im on Ubuntu 13.10
Project's author here. Just to let you know, finally, this (old) bug was fixed. Sorry for the inconvenience caused.
I'm still not sure if this has anything to do with an outdated module, or a messed up npm installation or maybe I'm just lucky, but basically the problem is that the path to access "data.json" is wrong (maybe not wrong but incomplete).
What I did was open file:
gksudo gedit /usr/local/lib/node_modules/jsonplaceholder/index.js
and modify the following function:
function reset() {
// server.low.load('data.json') <-- ORIGINAL LINE
server.low.load(require('path').resolve(__dirname, 'data.json')); //<--MY FIX
}
Just save the file, and run jsonplaceholder again.

Node.js forever module crashes on list

I'm running node v0.10.5 on Ubuntu 12.04, and I'm able to get processes started using the forever module, but as soon as I try to list the processes out, forever crashes with this error/stack trace:
/usr/local/lib/node_modules/forever/node_modules/nssocket/node_modules/lazy/lazy.js:211
for (var i = 0; i < chunk.length; i++) {
^
TypeError: Cannot read property 'length' of null
at Function.<anonymous> (/usr/local/lib/node_modules/forever/node_modules/nssocket/node_modules/lazy/lazy.js:211:38)
at Lazy.<anonymous> (/usr/local/lib/node_modules/forever/node_modules/nssocket/node_modules/lazy/lazy.js:187:21)
at Lazy.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (/usr/local/lib/node_modules/forever/node_modules/nssocket/node_modules/lazy/lazy.js:50:22)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:392:10)
at emitReadable (_stream_readable.js:388:5)
at Socket.Readable.read (_stream_readable.js:250:5)
at Socket.onSocketEnd (net.js:256:10)
at Socket.EventEmitter.emit (events.js:117:20)
I've tried upgrading it, and outright reinstalling it.
It's fixed. And i think will be released soon.
https://github.com/nodejitsu/forever/issues/408
or you can patch lazy.js manually
http://cl.ly/code/2k1I3A2r2v0k
Forever is still broken on node.js version 0.10. You install 0.8 via nvm for now

Error starting Juggernaut

When I try to start Juggernaut I get this error :
1 Apr 20:21:01 - socket.io ready - accepting connections
node_redis: no callback to send error: ERR unknown command 'subscribe'
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: ERR unknown command 'subscribe'
at RedisReplyParser.<anonymous> (/usr/local/lib/node/.npm/redis/0.5.9/packag
e/index.js:84:27)
at RedisReplyParser.emit (events.js:64:17)
at RedisReplyParser.send_error (/usr/local/lib/node/.npm/redis/0.5.9/package
/lib/parser/javascript.js:251:14)
at RedisReplyParser.execute (/usr/local/lib/node/.npm/redis/0.5.9/package/li
b/parser/javascript.js:110:22)
at RedisClient.on_data (/usr/local/lib/node/.npm/redis/0.5.9/package/index.j
s:328:27)
at Socket.<anonymous> (/usr/local/lib/node/.npm/redis/0.5.9/package/index.js
:99:14)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:672:14)
at IOWatcher.onReadable [as callback] (net.js:177:10)
I didnt find anything to help me!
Try upgrading Redis.
It happened to me, and that's what solved it. I'm using Ubuntu, and the one in the package manager isn't an updated version. It needs to be at least version 2.2.1.
Source: From one of the issues posted on the juggernaut github repo.
EDIT: Upon closer inspection, it looks like you were the one who posted the issue on the github repo. I'll just leave this answer here just in case anyone else has the same problem.

Resources