node-red-contrib-npm icon indicating copy to clipboard operation
node-red-contrib-npm copied to clipboard

ReferenceError: require is not defined

Open notownblues opened this issue 2 years ago • 0 comments

Hi there,

I'm trying to use the ldbs-json package for National Rail UK Live Board Departures but I'm struggling to get it to work with the npm-contrib node. The code I have works absolutely fine in the RunKit tool on the ldbs-json page but I get the error "ReferenceError: require is not defined" when I try to run the custom code in Node Red.

Any help would be greatly appreciated.

Code:

const useStaffVersion = false; const LiveDepartureBoardService = require('ldbs-json'); const token = "XXX-XXX-XXX-XXX"; // put a valid token here

// Set up the options for the call const options = { crs:"SVG", filterList: ["KGX"], time: "2020-04-14T08:30:00", timeWindow:120, timeOffset: 0 };

const api = new LiveDepartureBoardService(token, false); api.call("GetNextDeparturesWithDetails", options) .then(board => { console.log(board); }) .catch(error => console.error(error));

return npm_module(msg.payload);

image

notownblues avatar Sep 15 '22 10:09 notownblues