I am trying to access a standalone library in a function node and the approach shown in generic nodejs examples for the require command looks like this:
const sgMail = require('@sendgrid/mail');
I have added the following (including some other modules which work) to the .node-red folder in settings.js under functionGlobalContext:
sgMail: require('@sendgrid/mail')
and the following at the top of my function node:
var sgMail = global.get("@sendgrid/mail");
Then when this is executed:
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
It returns the following which I think indicates that the sendgrid module never got loaded.
"TypeError: Cannot read property 'setApiKey' of undefined"
Looking for advice and the meaning of the @ character in the require('@sendgrid/mail')
syntax.
Any help appreciated. - Thanks in advance.
Edit - This has also been added to the /.node-red folder's package.json file:
"dependencies": {
"@sendgrid/mail": "^7.2.6",
Node-RED version: v1.1.3
Node.js version: v10.22.0
Linux 5.4.0-1024-gcp x64 LE