Error: { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' } - node.js

Fotolog is closing recently and I wanted to backup all of mine photos on there. Looking for something useful, I found this project: https://github.com/firstdoit/fotolog-backup
I installed npm and coffee with the instructions on the readme
but when I try to run:
coffee fotolog-build-index.coffee ticinowriting2
I receive this error:
doc#doc-mtn:~/fotolog-backup$ coffee fotolog-build-index.coffee ticinowriting2
{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
The code in "fotolog-build-index" is:
request = require 'request'
$ = require 'cheerio'
fs = require 'fs'
imageURLs = []
user = process.argv[2]
throw new Error("Usage: coffee fotolog-build-index.coffee <username>") unless user
buildIndexFromPage = (page) ->
request "http://www.fotolog.com.br/#{user}/mosaic/#{page}", (err, resp, html) ->
return console.error(err) if err
console.log "finished page #{page}... adding images"
images = $.load(html)("a.wall_img_container img")
images.map (i,img) ->
imageURLs.push $(img).attr("src").replace('_t','_f')
if images.length < 30
console.log imageURLs
console.log "got #{imageURLs.length} images"
fs.writeFileSync('index.json', JSON.stringify(imageURLs))
else
buildIndexFromPage(page + 30)
buildIndexFromPage(0)
Sorry for my bad english, im from switzerland and i know quite nothing about this kind of code

That error means the DNS resolver could not resolve the hostname (www.fotolog.com.br) to an IP address. I can verify this is indeed the case (dig gets NXDOMAIN). So unless you have the IP address there's not much you can do.
You could try just www.fotolog.com since that does seem to resolve yet, however the message on that site indicates data should have been downloaded before February 20, 2016.

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?

How to track down error in node network code?

I am trying to track down why my code is failing with this error:
{ Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 443 }
and the stack trace for that error looks like this:
Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
I am making a network connection, but I am not trying to connect to localhost.
The network code I am using works just fine (and connects to the right host) in other contexts.
I'm using node 11.6.0 as supplied by brew install, and it looks like the only occurrence of the string "net.js" in the brew "Cellar" directory structure is in the node binary itself. In other words, even after
brew install --build-from-source node
running
find /usr/local/Cellar/node/11.6.0 -type f | xargs fgrep -l net.js
only finds one file: /usr/local/Cellar/node/11.6.0/bin/node and there's no net.* files in that directory tree.
If it matters, my code which seems to trigger this error looks like this:
const get_json_with_auth= async (channel, url) => {
const parsed_url= URL.parse(url);
return new Promise((good, fail) => {
let request= require('https').get({
hostname: parsed_url.hostname,
path: parsed_url.path,
headers: {
Authorization: get_auth('GET', channel, url)
}
});
console.log('url', url);
request.on('response', response=> {
const chunks= [];
response.on('data', data=> chunks.push(data));
response.on('end', ()=> good(JSON.parse(Buffer.concat(chunks).toString())));
});
request.on('error', err=> fail(err));
});
};
(I'm on OSX high sierra here.)
But, once again, the host name in the url I'm using does not resolve to localhost (and works just fine in other contexts).
How do I isolate a problem like this?
Running my code with the environmental variable NODE_DEBUG='net,tls,http,https' gave me enough information to recognize (and isolate) the problem.

How to read from a file where the filepath uses backward slashes?

In node.js, if I try to read from a file with backward slashes in the link (using fs module), I get this
Error: EISDIR: illegal operation on a directory, open 'C:\main\temp\config
1\folder\plugin\jquery-3.1.1.min.js'
at Error (native)
errno: -4068,
code: 'EISDIR',
syscall: 'open',
path: 'C:\\main\\temp\\config1\\folder\\plugin\\jquery-3.1.1.min.js' }
node.js code:
fs.readFile('C:\main\temp\config1\folder\plugin\jquery-3.1.1.min.js', function (err, data) {
});
Does anyone know how to fix it?
Thanks
Windows paths are supported by nodejs. You need to escape the backslashes:
fs.readFile('C:\\main\\temp\\config1\\folder\\plugin\\jquery-3.1.1.min.js', function (err, data) {
});

Node Cassandra driver just hangs on execute()

var cql = require('node-cassandra-cql');
var client = new cql.Client({hosts: ['*.*.*.*'], keyspace: '*',
username:'*', password: '*'});
console.log('connected to ' , client);
console.log('Querying....');
client.execute('select * from example where field1=?', [1],
function(err, result) {
console.log('inside', result);
if (err)
console.log('execute failed',err);
else
console.log('got chat ' + result.rows[0].field1);
client.shutdown();
}
);
I am using this code, the execute() callbacks aren't getting called . To test I used an incorrect IP address, it immediately responds and this line console.log('execute failed',err) logs what is below.
execute failed { [PoolConnectionError]
name: 'PoolConnectionError',
info: 'Represents a error while trying to connect the pool, all the connections failed.',
individualErrors:
[ { Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '*.*.*.*'
host: '*.*.*.*'
port: 9042 } ] }
If with right IP address nothing happens may because new cql.Client internally calls connect (asynchronously) before even connection is made execute is attempted ? All perfectly works in CQLSH, my servers are in AWS US west coast.
Any inputs welcome.
You are using the legacy Cassandra driver node-cassandra-cql, as the project readme states, it is no longer maintained:
node-cassandra-cql has graduated from community driver to being the
foundation of the official Datastax Node.js Driver for Apache Cassandra.
There will be no more development in this repository. I encourage
everyone to start migrating to the new driver as soon as you can, it's
got some great new features that you should try out, along with an
improved cql to javascript type mapping for prepared statements.
Use DataStax Node.js driver instead:
npm install cassandra-driver --save

RESTIFY: Error: socket hang up] code: 'ECONNRESET' on multiple requests

I am implementing a node app, which brings in order details from BigCommerce.
Multiple calls are made to BigCommerce API asynchronously using Restify JsonClient.
It works fine for some calls but after that i gives error: [Error: socket hang up] code: 'ECONNRESET', sslError: undefined, body: {}
I have tried turning off socket pooling ie by setting agent=false, but it still gives same error.
Following is code which makes call to BigCommerce API
makeRequest = function (url, params, headers, orderDetails, cb) {
var options = {
headers: headers
};
var client = restify.createJsonClient({
url: url
});
client.get(options, function(err, req, res, obj) {
if(err){
console.log(err);
cb(err,obj);
} else if(obj != null) {
var result = obj;
if(orderDetails == null) {
cb(null,result);
} else {
cb(null, result , orderDetails);
}
}
});
};
I get following error:
{ [Error: socket hang up] code: 'ECONNRESET', sslError: unde
fined, body: {} } Error: socket hang up
at SecurePair.error (tls.js:993:23)
at EncryptedStream.CryptoStream._done (tls.js:689:22)
at CleartextStream.read [as _read] (tls.js:490:24)
at CleartextStream.Readable.read (_stream_readable.js:320:10)
at EncryptedStream.onCryptoStreamFinish (tls.js:301:47)
at EncryptedStream.g (events.js:175:14)
at EncryptedStream.EventEmitter.emit (events.js:117:20)
at finishMaybe (_stream_writable.js:352:12)
at endWritable (_stream_writable.js:359:3)
at EncryptedStream.Writable.end (_stream_writable.js:337:5)
at EncryptedStream.CryptoStream.end (tls.js:628:31)
at Socket.onend (_stream_readable.js:483:10)
Why am i getting such error? How can i handle it?
Thanks
I just wanted to make sure that you're setting the agent setting in the right area.
Include the
"agent": false
in your options. (It's not set in the options in the code you pasted)
Per gfpacheco in the comments here: https://github.com/restify/node-restify/issues/485
By default NodeJS uses agents to keep the TCP connection open, so you can reuse it.
The problem is that if the server is closed, or it closes your connection for whatever reason you get the ECONNRESET error.
To close the connection every time you just need to set agent: false in your client creation
I've tried this solution and it worked for me.
Other than that, the
"secureOptions": "constants.SSL_OP_NO_TLSv1_2"
solution posted here sounds like it could be the right path, since you're getting an sslError.
Maybe you are running into this issue https://github.com/joyent/node/issues/5360
TL;DR: You could try with latest node version and secureOptions: constants.SSL_OP_NO_TLSv1_2 added to your options.

Resources