freightapis
v1.0.0
Published
Node.js SDK for FreightAPIs — NMFC freight classification, multi-carrier terminal locations, and global seaport data.
Maintainers
Readme
freightapis (Node.js)
Tiny, zero-dependency Node.js client for FreightAPIs — NMFC freight classification, multi-carrier terminal locations, and global seaports.
npm install freightapisRequires Node 18+ (uses the global fetch). On older Node, pass a fetch implementation via options.
Usage
const FreightAPIs = require('freightapis');
const fa = new FreightAPIs(process.env.FREIGHTAPIS_KEY);
// Carrier locations
const ga = await fa.carrierByStateOrZip('estes', { state: 'GA' });
const search = await fa.carrierSearch('saia', 'atlanta');
const cov = await fa.carrierCoverage('abf', { state: 'AR' });
const batch = await fa.carrierBatch('usps', { states: ['NY', 'NJ'] });
// Seaports
const cn = await fa.portsByCountry('CN');
const sh = await fa.port('CNSHA');
const near = await fa.portsNearby(31.2, 121.5, { radius: 200 });
const cosco = await fa.portsByCompany('COSCO');
// NMFC classification (Pro plan)
const cls = await fa.nmfcSearch('furniture');
const art = await fa.article('63321');
const dens = await fa.density({
dimensionType: 'Inch', weightType: 'Pound', resultUnitType: 'PoundsPerCubicFeet',
unitDimensions: [{ HandlingUnitCount: 1, length: 48, width: 40, height: 48, handlingUnitWeight: 500 }],
});
// Any endpoint not covered by a helper:
const days = await fa.request('GET', '/api/abf-location/service-days', { query: { zip: '72401' } });Errors
Non-2xx responses throw FreightAPIError with .status and .body:
const { FreightAPIError } = require('freightapis');
try {
await fa.article('does-not-exist');
} catch (e) {
if (e instanceof FreightAPIError) console.error(e.status, e.body);
}Options
new FreightAPIs(apiKey, { baseUrl: 'https://freightapis.dev', fetch: customFetch });API reference: https://freightapis.dev/docs · MIT licensed.
