I’m working with a Node.js TypeScript application that connects to Airtable’s API. My issue is that when I make a GET request, the data shows up perfectly in my server console, but when I try to access it through Postman or my frontend application, nothing comes back and the request eventually times out.
I think the problem might be with how I’m handling the response, but I’ve tried different approaches like promises and async/await without success.
Here’s my controller function that fetches data from Airtable:
import { Application, Request, Response } from 'express';
import { fetchUser } from '../controllers/users';
class ApiRoutes {
public setupRoutes = (app: Application): any => {
app.get('/user', fetchUser);
app.get('/user', (req: Request, res: Response) => {
fetchUser().then((result: any) => {
res.json(result);
});
});
};
}
export const apiRoutes = new ApiRoutes().setupRoutes;
The error I get in Postman says ‘socket hang up’. I can see the data being logged in my terminal, but the client never receives anything. What am I missing here?
Your fetchUser function doesn’t return anything - it just logs the data and exits. I hit this same issue with Airtable’s pagination. Your route handler calls fetchUser() but gets undefined back because eachPage is callback-based, not promise-based. The data shows up in your console but never reaches the response.
Also spotted you’ve got duplicate ‘/user’ routes. Express will only use the first one, so your second route with proper response handling might never run.
Besides the Promise wrapper fix mentioned above, you could try Airtable’s firstPage() if you just need the first batch, or all() to grab everything at once. Both return real promises that play nice with async/await.
The ‘socket hang up’ happens because your client’s waiting for a response that never comes, so the connection times out.
Your fetchUser function isn’t returning data to Express. The eachPage callback processes records but never sends them back through the response chain. I hit this same issue migrating from Airtable’s older SDK. The function runs fine (that’s why you see console logs) but returns undefined to your route handler. You’ve also got duplicate GET endpoints defined. Express uses the first one and ignores the second, so the version with res.json() never runs. Skip eachPage and use select().all() instead if you don’t need pagination: export async function fetchUser() { const userName = ‘Sarah’; try { const records = await database(‘Users’).select({ filterByFormula: {Username} = "${userName}" }).all(); return records.map(formatRecord); } catch (error) { throw error; } } This returns a proper promise your route handler can await and send back to the client.
Your fetchUser function isn’t returning anything to the client. The eachPage method is async but you’re not handling the response properly.
I hit this exact problem when I started with Airtable’s API. eachPage doesn’t return a promise with your data - it just processes records as it finds them.