Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeoJson from Geoserver using node.js

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.

like image 215
SSA Avatar asked Jul 13 '26 16:07

SSA


1 Answers

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'
}
like image 79
Robert Peters Avatar answered Jul 16 '26 08:07

Robert Peters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!