Netlify Deployment

Deploy static sites and serverless functions on Netlify.

Netlify CLI

npm i -g netlify-cli # install CLI
netlify login # authenticate
netlify init # initialize new site
netlify deploy # deploy draft
netlify deploy --prod # deploy to production

netlify.toml Config

[build]
  command = "npm run build"
  publish = "dist"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

[[headers]]
  for = "/*"
  [headers.values]
    X-Frame-Options = "DENY"

Environment Variables

# Add via UI or CLI
netlify env:set API_KEY secret123
netlify env:list # list all variables

# Access in build
process.env.API_KEY

Netlify Functions

# netlify/functions/hello.js
exports.handler = async (event) => {
    return {
        statusCode: 200,
        body: JSON.stringify({
            message: 'Hello'
        })
    };
};

# Available at:
/.netlify/functions/hello