Home > Software design >  Node Using JSON-Stat
Node Using JSON-Stat

Time:03-27

I am trying to use JSONStat toolkit for the first time. However I keep getting this error

        let method = init.method || input.method || 'GET';
                          ^

TypeError: Cannot read property 'method' of null
    at new Request (/app/node_modules/node-fetch/lib/index.js:1217:21)
    at /app/node_modules/node-fetch/lib/index.js:1439:19
    at new Promise (<anonymous>)
    at fetch (/app/node_modules/node-fetch/lib/index.js:1437:9)
    at module.exports (/app/node_modules/jsonstat-toolkit/main.cjs:2:15410)
    at Object.<anonymous> (/app/index.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)

code when running:

const JSONstat = require("jsonstat-toolkit");
JSONstat( "https://json-stat.org/samples/oecd-canada-col.json" , function() {
    if( this.class==="collection" ){
        var ds1=this.Dataset( 0 );
    }
} );

CodePudding user response:

You are trying to use the syntax for the v0.x of JSONstat. The example clearly shows the correct use.

Change this to be a parameter that you accept as an argument to the function:

const JSONstat = require("jsonstat-toolkit");
JSONstat( "https://json-stat.org/samples/oecd-canada-col.json" , function(j) {
    if( j.class==="collection" ){
        var ds1=j.Dataset( 0 );
    }
} );

Even with the correct code, version 1.4.1 seems to fail. Downgrading the package to 1.3.2 seems to fix it: npm i [email protected]. Alternatively, downgrade to version 0 and keep your same syntax (using this): npm un jsonstat-toolkit && npm i jsonstat.

  • Related