my sense is that last time we managed to
dotenv
and create a .env
file containing our API keyrequire('dotenv').config()
to load up our environment variables.I think maybe the next steps are these:
/airtable
route/airtable/:record_id
cli.js
file and npm link
to create commands?When we code our new routes, we'll end up with something like this for the /airtable
route:
router.get('/airtable', function(req, res, next) {
// go get some data from Airtable and render it
// look for stuff using record_id or other search term
var base = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base(process.env.AIRTABLE_WATCH_BASE);
var theRecords = [];
base('Media').select({
// Selecting most recent 1000 emoji
maxRecords: 100,
view: "Main View"
}).eachPage(function page(records, fetchNextPage) {
// go through each page and accumulate reactionType in theRecords array
theRecords.push(...records);
fetchNextPage()
}).then(()=>{
// now that you've accumulated all the records, render them
res.render('json', {
title: req.params.record_id,
timestamp: moment().format('YYYYMMDD-HHmmss.SSS'),
json: JSON.stringify(theRecords, null, 4)
})
}, function done(err) {
if (err) { console.error(err); return; }
});
});
and then something like this for the specific records:
router.get('/airtable/:record_id', function(req, res, next) {
var base = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base(process.env.AIRTABLE_WATCH_BASE);
base('Media').find(req.params.record_id, function(err, record) {
if (err) {
console.error(err); return;
}
console.log('Retrieved', record.id);
res.render('json', {
title: req.params.record_id,
timestamp: moment().format('YYYYMMDD-HHmmss.SSS'),
json: JSON.stringify(record, null, 4)
});
});
});
the 'json'
view file (i.e. /views/json.ejs
) I'm using just looks like this:
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1><%= title %></h1>
<h3><%= timestamp %></h3>
<p>Welcome to <%= title %></p>
<pre>
<%= json %>
</pre>
</body>
</html>