Movatterモバイル変換


[0]ホーム

URL:


Choose a framework to optimize documentation to:
    Advanced Node.js Usage

    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:

    1. From the dashboard, select your project and go to theSettings tab.
    2. Select Environment Variables from the left side in settings.
    3. 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.
    4. Pull your env vars into your local project with thefollowing command:
      terminal
      vercelenvpull

    For more information, seeEnvironment Variables.

    To install private npm modules:

    1. From the dashboard, select your project and go to theSettings tab.
    2. Select Environment Variables from the left side in settings.
    3. 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.
    4. 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:

    1. Add avercel-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"  }}
    1. Create the build script namedbuild.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!');});
    1. 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

    Previous
    Node.js
    Next
    Supported Node.js versions

    Was this helpful?

    supported.
    On this page

    [8]ページ先頭

    ©2009-2025 Movatter.jp