Is it possible to add an npm package to serverless?

Hello everyone! I am new to serverless / aws lambda and I have a few questions I wanted to ask. First off, is it possible;e for my lambda functions to utilize a js library? For example, if I wanted to us a package called Figlet in my code like such:
module.exports.funny = async (event) => {
var figlet = require(‘figlet’);
let data = figlet(‘Hello World!!’, function (err, data) {
if (err) {
console.log(‘Something went wrong…’);
console.dir(err);
return;
}
return data;
});

  return {
     statusCode: 200,
     headers: {
           "Access-Control-Allow-Origin": "*", // Required for CORS support to work
           "Access-Control-Allow-Credentials": true // Required for cookies, authorization headers with 
            HTTPS
     },
     data: JSON.stringify(data)
 }
}

And if so, how do I achieve this? Thank you very much!

Hi Selke and welcome to the community. It most definitely is possible to use npm modules. You would, however, preferably require your module outside the function instead. This is just a small optimisation. Otherwise you have it right. Just use them like you always have for Node.

See i tried doing this, and when I run the function it does not work. I have ruled out that I am not using the package correctly.

i’ve a question Do serverless provide a recommended way (architecture) to handle wildcard domains with api gateway? 9Appsapk.com VidMate.vin