3
votes

I am new to Node.js, learning with examples.

Here is what I am trying to do, I have a geoserver running to serve GeoJson, I want to call geoserver WFS url and get json data using node.js. Here is code, when I run it, I get :

getaddrinfo ENOENT

var http = require('http');


var options = {
    host: "local:8080/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=layername&outputFormat=JSON&cql_filter=id=1";
    path: '/'
}
var request = http.request(options, function (res) {
    var data = '';
    res.on('data', function (chunk) {
        data += chunk;
    });
    res.on('end', function () {
        console.log(data);

    });
});
request.on('error', function (e) {
    console.log(e.message);
});
request.end();

Please guide me in right direction. Thank you.

2

2 Answers

5
votes

You need to pass in the correct options:

host - should only be the host name

path - should the path to the resource on the host (all the stuff you have after the host name

method - should be GET or POST (GET in your case).

var options = {
    host: "local:8080";
    path: '/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=layername&outputFormat=JSON&cql_filter=id=1',
    method: 'GET'
}
0
votes

I was also trying to get a GeoJSON via Node.js and took a different approach; I used Express and sequelizejs. This allowed me to get objects directly from Postgres / PostGIS. I needed to do a little formatting client-side to form a valid GeoJSON from the express response.