Deploying Node.js serverless functions to Netlify involves a few steps.
Depending on your current situation, you can either
Let's walk through both scenarios.
Starting a New ProjectFor new workspaces you can create a Nx workspace with serverless function with one command:
❯
npx create-nx-workspace@latest my-functions --preset=@nx/netlify --site=my-site
Configure Existing ProjectsYou will need to install @nx/netlify
if you haven't already.
Next add the Netlify serverless configuration by running the following command:
❯
nx g @nx/netlify:setup-functions
This will do a few things:
src/functions
.netlify.toml
in the root of the projectproject.json
to have 2 new targets serve-functions
& deploy-functions
.To serve your functions locally, run:
Make sure you have a site configured on Netlify (skip if you have already). You have mostly two options:
npx netlify deploy
which will walk you through the processIf you run npx netlify deploy
in the workspace, the site ID will be automatically saved in the .netlify/state.json
file. Alternatively adjust the deploy-functions
in your project.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:
This creates a "draft deployment" to a temporary URL. If you want to do a production deployment, pass the --prod
flag:
❯
nx deploy-functions --prod
This invokes the "production" configuration of the deploy-functions
target and passes the --prod
flag to the Netlify CLI.
Configure your CI for automated deployments
Note that for a more stable and automated setup you might want to configure your CI to automatically deploy your functions.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4