smaver
smaver

Reputation: 19

Type Error: require(...) is not a function in SendGrid NodeJS

I am trying to send emails using the following doc on sendrid:

https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html

My app.js looks like this:

var sendgrid = require('sendgrid')('SENDGRID_APIKEY');

When runnig npm start I get the following error:

var sendgrid  = require('sendgrid')(conf);
                               ^
TypeError: require(...) is not a function
  at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\app.js:8:36)
  at Module._compile (module.js:409:26)
  at Object.Module._extensions..js (module.js:416:10)
  at Module.load (module.js:343:32)
  at Function.Module._load (module.js:300:12)
  at Module.require (module.js:353:17)
  at require (internal/module.js:12:17)
  at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\bin\www:7:11)
  at Module._compile (module.js:409:26)
  at Object.Module._extensions..js (module.js:416:10)

Any ideas what I am doing wrong? conf is a variable where I store my API key.

I am using a clean express installation.

THANKS

My package.json can be looked here as requested:

http://pastebin.com/pGKWFReX

Upvotes: 1

Views: 1806

Answers (1)

Akash
Akash

Reputation: 5221

The latest documentation shows a different structure for initialization.

You should try doing

var sg = require('sendgrid').SendGrid(conf);

Upvotes: 5

Related Questions