How to install npm Packages in HubSpot Serverless Functions?
Table of contents
Hey, HubSpot freaks!
If you are a regular reader of my blogs, then you might be familiar with the steps for creating serverless functions within your HubSpot account. Also, there are chances that you might have established a local environment for your business for better performance.
Moreover, you might be familiar with the concept that we are basically working in Node.js as our backend language, and HubSpot comes with some pre-installed node packages in HubSpot serverless functions to work with. But what if you want to have additional functionalities that only come from some other npm packages?
Yes! For this, you have to install npm packages as it will help you to access more functionality in your app. Let’s dive in to understand how to install npm packages in HubSpot.
All those who have worked with node will think that it’s an easy task, all you have to do is run npm commands in our CDM, and you will get all the access to packages in your app but guess what it is not that easy when it comes to serverless functions.
Yes! One needs to follow specific steps to install packages in HubSpot serverless function. Then only can we use those packages in our backend code?
Now, you might be thinking about how that is even possible in HubSpot CMS. Well! First things first.
You need to understand that we cannot do any process of installation of npm packages in HubSpot serverless functions without having permission from HubSpot.
Yes, that’s right! The serverless function is a new technology, and the best part is that HubSpot is providing it for free.
As the npm package installation feature is in the beta version, you have to register your portal for using this feature in your HubSpot account. After getting approved for installation, you have to follow some steps to get your npm packages working in your backend code.
Before we dive into the steps, let’s first look at some important changes/notes by considering which you can easily do the installation of npm packages without putting in much effort.
Things to consider before installing npm Packages
- Uploading .function folders no longer deploys them by default. The hs functions deploy command must be run, regardless of if a package.json file is included or not. At the moment, functions can only be deployed from the command line and not in the Design Manager UI.
- Each package is limited to 50MB in size (for now).
- @hubspot/api-client and Axios are included in packages by default, and they count toward the 50MB size limit. Versions can be overridden by specifying a version in package.json.
- There is a limit of 3 (for now) built packages per portal (each .functions folder with a deployed package.json counts as 1). Also, you can delete a .functions directory in your portal to reduce this number.
How to Install npm Packages in HubSpot
Follow the steps below to install npm packages in HubSpot
Step 1: Create a package.json File
Firstly, create a package.json file inside your serverless functions folder(in your local setup). Here make sure you include the name of packages that you want to install.


Example code of the package.json file will look like this.
{
“name”: “serverless”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1″
},
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“faker”: “^5.2.0”
}
}
All you need to do is to add the name of the package inside the dependencies section.
Like here, I have added the faker.js library.
Step 2: Run the hs upload Command
Once you are done with the naming, it’s time to run the hs upload command. It is basically done for uploading the local functions.

Step 3: Check the File
Many times, it is seen that people do not check the portal whether the folder is uploaded correctly or not.

Make sure you do not make this mistake.
Step 4: Replace the Demo File
Once you are done with the cross-checking, it’s time to replace the demo file code as follows:


Have a look at the below-added code-
const faker = require(‘faker’);
exports.main = (functionContext, sendResponse) => {
const { params } = functionContext;
sendResponse({ body: {
name: faker.name.findName(),
email: faker.internet.email(),
// This will include any query params added to the URL to the function output
params,
contactCard: faker.helpers.createCard()
}, statusCode: 200 });
};
Step 5: Run Functions
Now, it’s time to run hs functions and deploy serverless. functions as it will help you build and deploy the function remotely. This will read the /serverless.functions/package.json and install the specified dependencies for your function.
Moreover, this command will register the specified endpoints in serverless.functions/serverless.json.
You can refer to the below screenshot to get a clear insight about the same.

Step 6: Check the Endpoint Link
Almost, you are almost at the end stage of npm packaging. Now, you just have to hit your endpoint link inside any browser to check the results.

Congratulations! My friend. You have successfully installed npm packages in serverless functions. Now you can easily add more functionality by adding your favorite node modules inside the serverless functions.
The Final Say
There are no two opinions that serverless functions needless overhead and allow you to scale your business growth. Once you are able to build your serverless function and install npm pages in HubSpot, then you can easily extend the functionality like a pro.
Indeed, it’s not a cakewalk, but if you follow the above steps accordingly, then you can easily do the installation without any hassle.
So, what are you waiting for? Go Ahead and make the best use of serverless functions in HubSpot.
Are you still having any concerns? Feel free to contact us.
Editor– Divya Verma
Frequently Asked Questions
How to install HubSpot npm?
What are the limits for serverless functions HubSpot?
How do I create a serverless function in HubSpot?
What is a serverless function API?
Dive Into our Client Testimonials
Listen to business owners like you share how we’ve helped them grow. Your story could be next!
The webdew team is very supportive, they provide us with thoughtful suggestions.
We contracted webdew to build our new website. And let me tell you, they did a fantastic job. Their team was really easy to communicate with.”
The webdew team is very supportive, they provide us with thoughtful suggestions.
We contracted webdew to build our new website. And let me tell you, they did a fantastic job. Their team was really easy to communicate with.”
The webdew team is very supportive, they provide us with thoughtful suggestions.
We contracted webdew to build our new website. And let me tell you, they did a fantastic job. Their team was really easy to communicate with.”
“We worked with Chehak over the past several months to create a series of animated videos for an academic planner that we produce. And from the very beginning, she was absolutely professional and a pleasure to work with.”
6x
We helped clients multiply their website conversion rates through strategic design and UX optimization.
20%
Our marketing campaigns led to a 20% uplift in customer engagement across digital channels.
2K+
Delivered over 2,000 qualified leads through targeted funnels and smart automation.
120+
Our video content has earned 120,000+ views, driving brand awareness and audience retention.
“I recently had the pleasure of working with Chehak on a video demo project, and I was thoroughly impressed with her services.”
Additional Resources
Access expert tips, trends, and strategies designed for small businesses. Stay ahead of the curve and make informed decisions with our comprehensive resources!