Movatterモバイル変換


[0]ホーム

URL:


Skip to content
NxNxDocs
ContactTry Nx Cloud for free
GitHubYouTubeXDiscord

Deploying Node.js serverless functions to Netlify involves a few steps.

Depending on your current situation, you can either

  • create a brand new project with the intention of solely hosting and deploying Netlify functions
  • adding Netlify functions to an existing project

Let's walk through both scenarios.

For new workspaces you can create a Nx workspace with serverless function with one command:

npxcreate-nx-workspace@latestmy-functions--preset=@nx/netlify--site=my-site

You will need to install@nx/netlify if you haven't already.

nxadd@nx/netlify

Next add the Netlify serverless configuration by running the following command:

nxg@nx/netlify:setup-functions

This will do a few things:

  1. Create a new serverless function insrc/functions.
  2. Add thenetlify.toml in the root of the project
  3. Update yourproject.json to have 2 new targetsserve-functions &deploy-functions.

To serve your functions locally, run:

nxserve-functions

Make sure you have a site configured on Netlify (skip if you have already). You have mostly two options:

  • either go toapp.netlify.com and create a new site
  • use the Netlify CLI and runnpx netlify deploy which will walk you through the process

If you runnpx netlify deploy in the workspace, the site ID will be automatically saved in the.netlify/state.json file. Alternatively adjust thedeploy-functions in yourproject.json to include the--site flag:

project.json
{
"targets": {
...
"deploy-functions": {
"dependsOn": ["lint"],
"command":"npx netlify deploy --site=YOUR_SITE_ID",
"configurations": {
"production": {
"command":"npx netlify deploy --site=YOUR_SITE_ID --prod"
}
}
}
}
}

To deploy them to Netlify, run:

nxdeploy-functions

This creates a "draft deployment" to a temporary URL. If you want to do a production deployment, pass the--prod flag:

nxdeploy-functions--prod

This invokes the "production" configuration of thedeploy-functions target and passes the--prod flag to the Netlify CLI.

Note that for a more stable and automated setup you might want to configure your CI to automatically deploy your functions.


[8]ページ先頭

©2009-2025 Movatter.jp