Project: Netlify Functions airtable course tracker

Build: React, Netlify Serverless Functions, CSS, Node.js and REACT
Features: Serverless, airtable database, JAMstack
Deployment: Github and Netlify

Demo

Check out this video for more

This is from a tutorial from James Q Quick so shout out to him for this awesome idea.

Normally, to have this sort of dynamic content coming from a database you would need to know SQL a programming language for databases. It would probably take at least ten database tables. This would slow the site down, create some vulnerabilities and take a lot more man hours.

All we need to do bring in airtable.

require('dotenv').config();
var Airtable = require('airtable');
var base = new Airtable({ apiKey: process.env.AIRTABLE_API_KEY }).base(
    process.env.AIRTABLE_BASE_ID
);
const table = base(process.env.AIRTABLE_TABLE_NAME);

module.exports = { table };

Create

const { table } = require('./airtable');
const formattedReturn = require('./formattedReturn');
module.exports = async (event) => {
    const fields = JSON.parse(event.body);
    try {
        const createdCourse = await table.create([{ fields }]);
        return formattedReturn(200, createdCourse);
    } catch (err) {
        console.error(err);
        return formattedReturn(500, {});
    }
};

Delete

const { table } = require('./airtable');
const formattedReturn = require('./formattedReturn');
module.exports = async (event) => {
    const { id } = JSON.parse(event.body);
    try {
        const deletedCourse = await table.destroy(id);
        return formattedReturn(200, deletedCourse);
    } catch (err) {
        console.error(err);
        return formattedReturn(500, {});
    }
};

Get

const { table } = require('./airtable');
const formattedReturn = require('./formattedReturn');
module.exports = async (event) => {
    try {
        const courses = await table.select().firstPage();
        const formattedCourses = courses.map((course) => ({
            id: course.id,
            ...course.fields,
        }));
        return formattedReturn(200, formattedCourses);
    } catch (err) {
        console.error(err);
        return formattedReturn(500, {});
    }
};

Update

const { table } = require('./airtable');
const formattedReturn = require('./formattedReturn');
module.exports = async (event) => {
    const { id, ...fields } = JSON.parse(event.body);
    try {
        const updatedCourse = await table.update([{ id, fields }]);
        return formattedReturn(200, updatedCourse);
    } catch (err) {
        console.error(err);
        return formattedReturn(500, {});
    }
};

Jamstack web app based on air table
The finished app

Air Table Database
The Air Table Database


Visit https://chrisconnelly.dev for more