Advanced Node.js Usage
Last updated July 30, 2025
To use Node.js, create a file inside your project's api directory. No additional configuration is needed.
The entry point for src must be a glob matching .js, .mjs, or .ts files that export a default function.
To disable helpers:
- From the dashboard, select your project and go to the Settings tab.
- Select Environment Variables from the left side in settings.
- Add a new environment variable with the Key:
NODEJS_HELPERSand the Value:0. You should ensure this is set for all environments you want to disable helpers for. - Pull your env vars into your local project with the following command:
terminal
vercel env pull
For more information, see Environment Variables.
To install private npm modules:
- From the dashboard, select your project and go to the Settings tab.
- Select Environment Variables from the left side in settings.
- Add a new environment variable with the Key:
NPM_TOKENand enter your npm token as the value. Alternatively, defineNPM_RCas an Environment Variable with the contents of~/.npmrc. - Pull your env vars into your local project with the following command:
terminal
vercel env pull
For more information, see Environment Variables.
In some cases, you may wish to include build outputs inside your Vercel Function. To do this:
- Add a
vercel-buildscript within yourpackage.jsonfile, in the same directory as your Vercel Function or any parent directory. Thepackage.jsonnearest to the Vercel Function will be preferred and used for both installing and building:
package.json
{
"scripts": {
"vercel-build": "node ./build.js"
}
}- Create the build script named
build.js:
build.js
const fs = require('fs');
fs.writeFile('built-time.js', `module.exports = '${new Date()}'`, (err) => {
if (err) throw err;
console.log('Build time file created successfully!');
});- Finally, create a
.jsfile for the built Vercel functions,index.jsinside the/apidirectory:
api/index.js
const BuiltTime = require('./built-time');
module.exports = (request, response) => {
response.setHeader('content-type', 'text/plain');
response.send(`
This Vercel Function was built at ${new Date(BuiltTime)}.
The current time is ${new Date()}
`);
};When a SIGINT signal is sent to a Node.js function, it will terminate every function running on that Fluid instance. When implementing graceful shutdown patterns in your Node.js functions, keep this instance-wide termination behavior in mind.
Was this helpful?