Gets a random Psalm from the ESV API using Netlify Functions
-
Install Netlify CLI globally so you can use netlify-dev
-
You should be logged in on Netlify CLI
-
Your project should be linked to a
siteID
on Netlify (usingnetlify init
ornetlify link
). You can confirm this has been done if you have a.netlify
folder with astate.json
file containing yoursiteID
. -
run
npm install
to getnode-fetch
which you'll need to fetch things inside your function -
add your api key to your netlify environmental variables in the netlify settings ui (your site > site settings > build & deploy > environmental variables)
-
create a
functions/
folder at the root and put your{FUNCTION NAME}.js
file there -
add
netlify.toml
pointing tofunctions/
folder -
run
netlify dev
to have a local server and be able to access functions- view your site at
http://localhost:8888
- the functions will be accessible at
http://localhost:8888/.netlify/functions/function-name
.
- view your site at
Basic function calling an api with javascript and node-fetch (this is the example you get when you run netlify functions:create
and choose node-fetch
)