DEV Community

Chris Connelly
Chris Connelly

Posted on

Using .ENV to Hide Your Air Table Credentials In React

Create a dotenv file

First you'll want to create a .env file

AIRTABLE_API_KEY=xxxxxxxxxx
AIRTABLE_BASE_ID=appxxxxxx
AIRTABLE_TABLE_NAME=base-1
Enter fullscreen mode Exit fullscreen mode

Install dotenv

Once you have this created you can use it by installing dotenv

npm -i dotenv
Enter fullscreen mode Exit fullscreen mode

Set up dotenv in airtable.js

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 };
Enter fullscreen mode Exit fullscreen mode

Top comments (0)