I am given this task to perform some stuff with data obtained from an AirTable API with NodeJS. I am using the AirTableJS node library with the DefinitelyTyped airtable definitions (I am using NestJS).
So, naturally, I do the following to import the necessary packages.
yarn add airtable @types/airtable
Then, in my repository that interacts with the AirTable API, I have the following.
import { User } from "../entities/user";
import { ConfigService } from "@nestjs/config";
import { Inject, Injectable } from "@nestjs/common";
import { LogService } from "src/log/services/log/log.service";
import { Base } from "airtable";
@Injectable()
export class UsersRepository {
private readonly apiKey: string;
private readonly baseId: string;
constructor(@Inject(ConfigService) private readonly config: ConfigService, @Inject(LogService) private readonly log: LogService) {
this.apiKey = this.config.get<string>('airtable.apiKey');
this.baseId = this.config.get<string>('airtable.baseId');
}
async getUnmatchedUsers(): Promise<User[]> {
const base: Base = new Airtable({apiKey: this.apiKey}).base(this.baseId);
// other code here
}
}
But, when running it, I get the following error relating to the repository function:
ReferenceError: Airtable is not defined
Am I missing anything here or did I not import the Airtable package correctly?
Thanks.
It's not defined because you haven't imported Airtable
.
That's probably going to look like:
import Airtable, { Base } from "airtable";