API

Local Environment variables

Kickstart using dotenv to setup environment variables for local development.

Below is the sample template inside api/.env file.

WEBAPP_URL=http://localhost
WEBAPP_PORT=3000
API_URL=http://localhost
API_PORT=3333
FIREBASE_DATABASE_URL=YOUR_FIREBASE_DATABASE_URL
FIREBASE_PROJECT_ID=YOUR_FIREBASE_PROJECT_ID
FIREBASE_STORAGE_BUCKET=YOUR_FIREBASE_STORAGE_BUCKET
FIREBASE_PRIVATE_KEY=YOUR_FIREBASE_PRIVATE_KEY
FIREBASE_CLIENT_EMAIL=YOUR_FIREBASE_CLIENT_EMAIL
STRIPE_SECRET=YOUR_STRIPE_SECRET
STRIPE_WEBHOOK_SECRET=YOUR_STRIPE_WEBHOOK_SECRET
SENTRY_DSN=YOUR_SENTRY_DSN

NPM Custom Scripts

Kickstart API comes with several handly scripts for development or production.

npm run build - Compile typescript files into js files
npm run clean - Remove the compiled js files, node_modules, and package/yarn lock files
npm run dev - Running the API server in development
npm run fix - Fix the code syntax and issues
npm run sort - Sort the package.json setting
npm run start - Running the API server in production
npm run webhook - Running the stripe webhook mock server for sending webhook request locally

Start Stripe Webhooks Server Locally

In order to test our stripe webhook locally, we need to install Stripe CLI in our local machine.

Head over the stripe doc to install it.

Forward webhooks to the local server

stripe listen --forward-to localhost:3333/hooks

Record down the webhook signing secret and paste it into the api/.env file.

Start API server in local development

Install dependency packages first

npm install

Now compile typescript into js

npm run build

Start API server in local development

npm run dev

Setup Git Repo

Setup the local git repo

cd api
git init
git add .
git commit -m "First commit"

Setup Github Repo

Login to Github and create a new repo.

Go back to the terminal to add GitHub repo to the origin and push the code to Github repo.

git remote add origin https://github.com/timshingyu/kickstart-demo-api.git
git push -u origin master