[ netlify ] function

site/netlify.toml

[build]
  # add function folder
  functions = "functions"

public/_redirect

/hello /.netlify/functions/hello 200

Create netlify function

netlify functions:create hello
Created functions/hello/hello-world.js
async function hello() {
  return Promise.resolve("Hello, World");
}

exports.handler = async function(event, context) {
  try {
    const body = await hello();
    return { statusCode: 200, body };
  } catch (err) {
    return { statusCode: 500, body: err.toString() }:
  }
}

Test URL : http://localhost:8000/.netlify/functions/hello

netlify functions:create fauna
template : js-fauna-crud # install npm fauna ( object database ) and create fauna CRUD endpoint

Turn it into npm project

npm init
npm i random-name

Give the random first name

const random = require('random-name')
random.first()

ref : https://www.netlify.com/docs/functions/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s