I want to extend the functionality by creating a sendmail endpoint. I created a new file called sendMail.js and registered a new GET-Endpoint.
The endpoint was correctly initialized. To send an email i want to use nodemailer. I added the package wir "yarn add nodemailer" and imported the mailer in my sendMail.js.
Installing dependencies (in particular, "nodemail") via
$ npm install --save
Third, we run webpack on this app:
$ webpack --config webpack.config.js
Webpack has now compiled the node app into a flat file "bundle.js" (as per my config file), which contains close to 1 Million characters of gibberish (i.e. compiled javascript, including all nested dependencies of the app):
Fourth and finally, we take this ENTIRE output and paste it into "File #1" (where I had placed the comment):
Now when I route a GET request to the function handler in "File #1", I get a successfull response:
Yippieh! I hope these steps are helpful for implementing webpack with HubSpot Serverless.
to the webpack configuration file after seeing some rather gruesome access errors. I implemented this fix as per https://github.com/googleapis/google-api-nodejs-client/issues/1732 , but I haven't checked whether I actually broke the functionality of nodemail.js this way. So this solution might need some more work, but I hope it illustrates the general approach.
Thanks to HubSpotters Mike (@mgallant23) and Derek (@dgervais), whose internal resources on this topic I have relied on in preparing this solution.
Valentin, feel free to get in touch with any further questions on this topic.
Installing dependencies (in particular, "nodemail") via
$ npm install --save
Third, we run webpack on this app:
$ webpack --config webpack.config.js
Webpack has now compiled the node app into a flat file "bundle.js" (as per my config file), which contains close to 1 Million characters of gibberish (i.e. compiled javascript, including all nested dependencies of the app):
Fourth and finally, we take this ENTIRE output and paste it into "File #1" (where I had placed the comment):
Now when I route a GET request to the function handler in "File #1", I get a successfull response:
Yippieh! I hope these steps are helpful for implementing webpack with HubSpot Serverless.
to the webpack configuration file after seeing some rather gruesome access errors. I implemented this fix as per https://github.com/googleapis/google-api-nodejs-client/issues/1732 , but I haven't checked whether I actually broke the functionality of nodemail.js this way. So this solution might need some more work, but I hope it illustrates the general approach.
Thanks to HubSpotters Mike (@mgallant23) and Derek (@dgervais), whose internal resources on this topic I have relied on in preparing this solution.
Valentin, feel free to get in touch with any further questions on this topic.
Jul 11, 20227:23 AM - edited Jul 11, 20227:23 AM
HubSpot Employee
Import packages in serverless functions
SOLVE
Hello @Megh_Patel , I would recommend you pose your question as a new forum post or on our developer Slack server. I would also recommend you provide some additional detail there on steps you have already tried, on the runtime and packages that comprise your app, on any errors you are getting, etc.
I checked in this case with my team and was able to confirm that at the moment, we do not support the defining of any node dependencies. We only support a small list of dependencies built-in. You can check out the list here.
As such, if you'd like to use the dependency, you would need to use something like webpack to bundle the dependency into your function.
While we currently do not have any real resources on that front just yet, do let us know if your team run into any specific issues bundling the dependency.