Advanced Node.js Usage
To use Node.js, create a file inside your project'sapi
directory. No additional configuration is needed.
The entry point forsrc
must be a glob matching.js
,.mjs
, or.ts
files that export a default function.
To disablehelpers:
- From the dashboard, select your project and go to theSettings tab.
- Select Environment Variables from the left side in settings.
- Add a new environment variable with theKey:
NODEJS_HELPERS
and theValue: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 thefollowing command:terminal
vercelenvpull
For more information, seeEnvironment Variables.
To install private npm modules:
- From the dashboard, select your project and go to theSettings tab.
- Select Environment Variables from the left side in settings.
- Add a new environment variable with theKey:
NPM_TOKEN
and enter yournpm token as the value. Alternatively, defineNPM_RC
as anEnvironment Variable with the contents of~/.npmrc
. - Pull your env vars into your local project with thefollowing command:terminal
vercelenvpull
For more information, seeEnvironment Variables.
In some cases, you may wish to include build outputs inside your Vercel Function. To do this:
- Add a
vercel-build
script within yourpackage.json
file, in the same directory as your Vercel Function or any parent directory. Thepackage.json
nearest 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
constfs=require('fs');fs.writeFile('built-time.js',`module.exports = '${newDate()}'`, (err)=> {if (err)throw err;console.log('Build time file created successfully!');});
- Finally, create a
.js
file for the built Vercel functions,index.js
inside the/api
directory:
api/index.js
constBuiltTime=require('./built-time');module.exports= (request, response)=> {response.setHeader('content-type','text/plain');response.send(` This Vercel Function was built at${newDate(BuiltTime)}. The current time is${newDate()} `);};
Last updated on June 25, 2025
Was this helpful?
On this page