Why does the errno in node-webkit differ from Node.js? - node.js

Run the same code in node-webkit and Node.js
var fs = require('fs')
// var fs = process.mainModule.exports.fs // node-webkit
fs.readFile('/xxxx/xx','utf-8', function (e) {
console.log(e)
})
In Node.js, the errno is 34
{ [Error: ENOENT, open '/xxxxx/xx'] errno: 34, code: 'ENOENT', path: '/xxxxx/xx' }
In node-webkit, it's -2
{"errno":-2,"code":"ENOENT","path":"/xxxx/xx"}
Why the errnos are different?
Is there a errno cheat sheet for node-webkit like this one for Node.js?

I'm having the same error and its due to using a relative path. Try to reading fro xx directly, not from /xxxx/xx
Hope it solves it

Related

fs.readFileSync throwing errno 4058

When I try to access the json file iike this:
...
var configurationFile = fileSystem.readFileSync(
"../configurationFile.json"
);
var apiSecretKey = JSON.parse(configurationFile.toString()).secret;
var url = JSON.parse(configurationFile.toString()).db_url;
var dbName = JSON.parse(configurationFile.toString()).db_name;
...
i get this error
Error: ENOENT: no such file or directory, open '../configurationFile.json'
at Object.<anonymous> (C:\Users\Samuel\Documents\GitHub\project-1\Back-End\API\Services\loginservice.js:7:36)
...
at Object.<anonymous> (C:\Users\Samuel\Documents\GitHub\project-1\Back-End\index.js:11:26) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '../configurationFile.json'
this is the dir structure
API
...Services
......loginservice.js
...configurationFile.js
index.js
How do i get around this besides this wrapping the config in a module. Is this a windows specific issue?

Error when running js on mac via node.js. How to fix?

I have created a .js file in a text editor and tried to run it via node js:
var pizzaDoge = require('fs')
pizzaDoge.writeFile("/index.html", "<h1>doge is fat</h1>", function(error) {
if (error) {
return console.log(error)
} else {
return console.log("you fed the doge!")
}
})
when I try to run the program using node using "node index.html" in the command line software this pops out
{ Error: EACCES: permission denied, open '/index.html'
errno: -13,
code: 'EACCES',
syscall: 'open',
path: '/index.html' }
just in case the error no. matters to which computer I am using I use Mac. Thanks for the help.
On Mac, the root folder(/) requires root permission to access
Please try to use ./index.html instead of /index.html for creating files under your current folder

NodeJS: readdir() returns "undefined" instead of the list of files?

I'm trying to check how many files does have a directory using NodeJS's File System.
var fs =require('fs');
function listaArchivos(directorio){
fs.readdir(directorio, function(err, archivos){
if(!err) {
console.log(archivos);
} else {console.log(err)}
})
}
var directorio = 'home/Rosamunda/Desktop/coderhouse/fs/';
listaArchivos(directorio);
I receive this error:
{ [Error: ENOENT, readdir 'home/Rosamunda/Desktop/coderhouse/fs/']
errno: 34,
code: 'ENOENT',
path: 'home/Rosamunda/Desktop/coderhouse/fs/' }
I've tried to search for that ENOENT error, and what I do understand is that the error appears when the path is incorrect, but the path does exist. If I try to print archivos, it returns "undefined".
ENOENT means the path doesn't exist. It looks like you may be missing the / at the beginning of the path (to make it an absolute path).

Error in fs.readFileSync() in nodejs

I am calling a sync call using require('fs'); in nodejs
var folder_path = '/home/abc';
var myfiles = ['a.png','b.png'];
_.each(myfiles, function(name){
var data = fs.readFileSync(folder_path+'/'+name);
if(data){
// Some operation
}
});
while calling that function i'm getting Error: EISDIR, illegal operation on a directory
fs.js:488
var r = binding.read(fd, buffer, offset, length, position);
^
Error: EISDIR, illegal operation on a directory
at Object.fs.readSync (fs.js:488:19)
at Object.fs.readFileSync (fs.js:322:28)
at /home/coader/dev/api/controllers/MyController.js:66:30
at Function.forEach ( /home/coader/dev/node_modules/sails/node_modules/lodash/dist/lodash.js:3298:15)
at /home/coader/dev/api/controllers/MyController.js:41:11
at Object.oncomplete (fs.js:108:15)
error: Forever detected script exited with code: 8
Details
$ node -v
v0.10.37
$ nodejs -v
v0.10.37
$ npm -v
1.4.28
Any answer will be appreciable.
Thanks
I think you might have to settle for "myfiles.forEach(function(name)"
var folder_path = '/home/abc';
var myfiles = ['a.png','b.png'];
myfiles.forEach(function(name){
var data = fs.readFileSync(folder_path+'/'+name);
if(data){
// Some operation
}
});

node.js fs rename ENOENT

I am trying to write a handler for file uploads in node.js using express framework. Following is the raw skeleton of it.
exports.handleUpload = function(req,res){
var temp_path = req.files.doc.path,
target_path = './uploads/' + req.files.doc.name ;
fs.rename(temp_path, target_path, function(err){
if(err){
console.log(err);
}
fs.unlink(temp_path, function(){
if(err){
console.log(err)
}
})
//Do stuff
})
}
However I get an error in the execution of renmae function occassionally(not always), especially with uploads of large files.
This is what the console caches from the error code
{ [Error: ENOENT, rename '/tmp/16368-19661hu.pptx'] errno: 34, code: 'ENOENT', path: '/tmp/16368-19661hu.pptx' }
From : https://github.com/joyent/node/blob/master/deps/uv/include/uv.h
XX(ENOENT, "no such file or directory")
The uploads/ directory does exist and permissions isn't an issue. Had it been so, it would have been failing each time, but it does not.
You're using the /tmp directory. The OS might be deleting the files since it can do so for the /tmp directory, hence the "randomness" of the issue. Use fs.exists before doing your other operations.

Resources