I was wondering, I am new to Hubspot development, and I would like to know, how would I store my access token as an environment variable (no hardcoding). We eventually want to put this code on a live server, and for security reasons I don’t want to have a hardcoded access token in my code. All the information on the web seems to only talk about the old method of API keys.
This is my current code:
const express = require(‘express’);
const axios = require(‘axios’);
const app = express();
const hubspot = require(‘@hubspot/api-client’);
const private_app_token = ‘my_token’
const hubspotClient = new hubspot.Client({“accessToken”:private_app_token});
const companyIdConst = window.location.href.lastIndexOf(‘/’) + 1;
app.get(‘/companies’, async (req, res) => {
const companyId = companyIdConst;
const properties = [“zip”];
const propertiesWithHistory = undefined;
const associations = undefined;
const archived = false;
const idProperty = undefined;
try {
const apiResponse = await hubspotClient.crm.companies.basicApi.getById(companyId, properties, propertiesWithHistory, associations, archived, idProperty);
const data = apiResponse.results;
//res.json(data);
console.log(JSON.stringify(apiResponse.properties.zip, null, 2));
} catch (e) {
e.message === ‘HTTP request failed’
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}
});
app.listen(3000, () => console.log(‘Listening on http://localhost:3000’));