Skip to content

karlyanelson/vanillajsacademy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vanillajsacademy

Install Dependencies

npm install

Run Locally

Not using a netlify function:

If you're not using netlify functions, you can just run it this way:

npm run serve

serves at

http://localhost:8080/vanillajsacademy/

If using a netlify function:

If you're using netlify functions, you need to run it like this:

netlify dev

serves at

http://localhost:8888/vanillajsacademy/

How to use Netlify Functions to make secure API calls

  1. Install Netlify CLI globally so you can use netlify-dev

  2. You should be logged in on Netlify CLI

  3. Your project should be linked to a siteID on Netlify (using netlify init or netlify link). You can confirm this has been done if you have a .netlify folder with a state.json file containing your siteID.

  4. run npm install to get node-fetch which you'll need to fetch things inside your function

  5. add your api key to your netlify environmental variables in the netlify settings ui (your site > site settings > build & deploy > environmental variables)

  6. create a functions/ folder at the root and put your {FUNCTION NAME}.js file there

  7. add netlify.toml pointing to functions/ folder

  8. 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.

Resources

Netlify Functions Docs

netlify-dev Docs

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)

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published