Error: ESPIPE, write - javascript

Im using the following code to write to a file
fs.writeFile('/dev/ttymxc1',"LED 1 ON",function(err){
if (err) return console.log(err);
});
and I get the error
{ [Error: ESPIPE, write] errno: -29, code: 'ESPIPE' }
I already googled it but I found nothing..
EDIT:
I think the reason this does not work it that I have to use
fs.createWriteStream();
instead of
fs.fileWrite();

The Solution was using
fs.createWriteStream()
instead of
fs.fileWrite();

Related

How to access a NodeJS exception text programmatically

The exception object in NodeJS has an unusual structure. I'd like to be able to access the error message, but it's not a named attribute of the object. For example:
var fs = require("fs");
function main() {
"use strict";
try {
var stats = fs.statSync("./nonexistantFile.txt");
console.log(stats);
}
catch (exception) {
console.error("exception: " + JSON.stringify(exception));
console.log(exception);
}
};
main();
This code prints the following output:
exception: {"errno":-2,"code":"ENOENT","syscall":"stat","path":"./nonexistantFile.txt"}
{ [Error: ENOENT: no such file or directory, stat './nonexistantFile.txt']
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: './nonexistantFile.txt' }
You can see that console.log() is printing an error text message in a way that makes it appear to be part of the object. Is that text part of the exception object? Or is it something that console.log() is adding?
I would like to be able to capture the error text message and store it. How do I access that message?
Just use exception.message.
More information can be found here: Error at MDN Web Docs

Facing issue in using mv() module in node

encountering with error ENOENT : rename filename,
am unable to understand this error why am facing can anyone help me out.
below is my code
mv(query.sourceLocation, query.targetLocation, {
mkdirp: true
}, function (err) {
if (err) return console.error(err+new Date());
res.end("moved");
});

Socketio: Error: Lone surrogate U+D83D is not a scalar value

recently my node.js server has been crashing a lot due to this socket.io error. My suspicion is that client is sending invalid utf string, which will throw an error in the utf8.js file. Is there a way to avoid server crash? It's very frustrating. I'm down to monkey patch this file if needed.
Error: Lone surrogate U+D83D is not a scalar value
at Error (native)
at checkScalarValue (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/node_modules/utf8/utf8.js:69:10)
at encodeCodePoint (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/node_modules/utf8/utf8.js:90:4)
at Object.utf8encode [as encode] (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/node_modules/utf8/utf8.js:111:18)
at Object.exports.encodePacket (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:74:34)
at encodeOne (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:387:13)
at eachWithIndex (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:256:5)
at map (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:263:5)
at Object.exports.encodePayloadAsBinary (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:411:3)
at Object.exports.encodePayload (/root/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:225:20)
at XHR.Polling.send (/root/node_modules/socket.io/node_modules/engine.io/lib/transports/polling.js:238:10)
at Socket.flush (/root/node_modules/socket.io/node_modules/engine.io/lib/socket.js:341:20)
at Socket.sendPacket (/root/node_modules/socket.io/node_modules/engine.io/lib/socket.js:317:10)
at Socket.send.Socket.write (/root/node_modules/socket.io/node_modules/engine.io/lib/socket.js:290:8)
at writeToEngine (/root/node_modules/socket.io/lib/client.js:148:17)
at Client.packet (/root/node_modules/socket.io/lib/client.js:159:7)
Probably you are trying to send your data in some wrong way.
You could try to have a try {} catch (e) {} around your Client/socket.packet, or do something like this:
process.on('uncaughtException', (err) => {
console.log(`Caught exception: ${err}`);
});
To prevent the server from dieing.

Hostname/IP doesn't match certificate's altnames - error while making https request

I am using node.js library called urllib (https://github.com/node-modules/urllib) to make http requests. But when I try to run the code I am getting below error:
Error: Hostname/IP doesn't match certificate's altnames
at SecurePair.<anonymous> (tls.js:1379:23)
at SecurePair.EventEmitter.emit (events.js:92:17)
at SecurePair.maybeInitFinished (tls.js:982:10)
at CleartextStream.read [as _read] (tls.js:469:13)
After my research, I found out that I need to add an option called rejectUnauthorized:false. So I added same using below code:
urllib.request(urlToCall, { rejectUnauthorized:false }, function (err, data, response) {
if(err) {
throw err;
}
});
But still I get the same error. Can anyone please guide me how to resolve this error? Since I am beginner to node and this error looks very strange to me, by the way I am using Ubuntu 12.0.4 LTS OS.

How do I fix this error with node.js and node-imagemagick: Error: Command failed: execvp(): Permission denied?

Im getting this error:
Error: Command failed: execvp(): Permission denied
When I do a simple node-imagemagick script:
im = require('imagemagick');
im.identify.path = '/tmp/node_thumbs/';
im.identify('cool.jpg',function(err,features){
if(err) throw err;
console.log(features);
});
Any ideas on what could be causing this?
The permission denied is from trying to launch the ImageMagick command, not in the process of executing it.
If you look at the documentation, identify.path is "Path to the identify program." In this case, you're redefining the path to the executable as /tmp/node_thumbs/, which presumably is not the executable.
You probably simply want:
var im = require("imagemagick");
im.identify('/tmp/node_thumbs/cool.jpg',function...

Categories

Resources