google-cloud-node: Can't connect to local Datastore Emulator
Hi, I just updated from 0.29 to 30.3 and I can’t connect to the Datastore emulator locally. This is the steps I do:
Launch datastore with:
gcloud beta emulators datastore start --project=my-project-id --data-dir /path/to/some/dir --host-port localhost:8380
It launches and tells me:
API endpoint: http://localhost:8380/datastore
...
Dev App Server is now running
Init gcloud-node with
var config = {
projectId: 'my-project-id',
// keyFilename: '/some/path/to/credential.key.json', (tried both with and without)
};
var gcloud = require('gcloud')(config);
var datastore = gcloud.datastore({
apiEndpoint: "http://localhost:8380"
});
Create an Entity
var key = datastore.key('BlogPost');
datastore.save({
key: key,
data: {
title: 'Hello world'
}
}, function(err) {
console.log(key.path);
});
I receive this in err: “{“code”:503,“metadata”:{”_internal_repr":{}}}"
I then changed the apiEndPoint to “http://localhost:8380/datastore” (as indicated when launching the emulator) but then it blocks the request (does not come into the callback) and in the terminal it says:
E0414 09:11:46.140609000 4406423552 resolve_address_posix.c:126] getaddrinfo: nodename nor servname provided, or not know
As I said, I tried both with and withouth credentials without any difference.
Some help would be greatly appreciated! 😃 Thanks a lot for this great library.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 16 (11 by maintainers)
I was able to find a workaround (thanks for a theory from @pcostell that it may be an ipv6 issue).
First, run the emulator with
--no-legacy
:Then use
127.0.0.1
instead oflocalhost
:Of course, replace
<port>
by whatever was output bygcloud
(or force a port in the emulator with --host-port)It sounds like this may be an ipv4 vs ipv6 issue.
A note if it’s helpful, the gcloud emulator supports ipv6 hostnames starting in gcloud 116.0.0:
gcloud beta emulators datastore start --no-legacy --host-port "[::1]:8080"
But it seems like gcloud-node is trying to connect over ipv6 to localhost, whereas the emulator is serving on ipv4.