Demonstrates
- How to structure a static website with Javascript in the browser that also uses Node for automation
- How to use Node to create a test web server thus avoiding CORS issues with external data on localhost
- How to use Node to import CSV, convert to JSON, and write to a .json file
- How to use Node to import data from Google Sheets
- How to create a file for secure, platform-specific, data and ignore it with Git
- Static website: e.g.
/index.html
and/assets/*
which uses external data - To convert CSV to JSON data: In
node-projects/convert-csv-to-json/
, usenode index.js
- Node test server to call
fetch()
and import data from the same origin, avoiding CORS issues
The test server inside node-projects/test-server/
sets the entire project Git repository folder "public" so that
- All assets (e.g.
node-projects/convert-csv-to-json/data.json
) can be accessed via their expected paths in your code without CORS issues - When you finish your project and put it on a live server (e.g. Github.io) the paths will still work
- If you access files via
file:///path/to/project/index.html
thenfetch()
will fail because of CORS
- Change to server directory
cd node-projects/test-server/
(you must run from this directory) - Start the server
node server.js
- View
/index.html
at https://localhost:3000/
To keep from committing files with sensitive data into your repo just copy and paste the names of these file to the .gitignore
.
- Create a
.gitignore
file - Add the names of the files to the
.gitignore
credentials.json
token.json
This is a common method for securing platform-specific data, and could be done with any type of file. Is it common across node developers to use an .env
(short for "environment") file. Check out this article Here’s how you can actually use Node environment variables