Node.js Quickstart Guide
Get started with CarsXE's Node.js SDK to integrate comprehensive vehicle data into your JavaScript and TypeScript applications.
The CarsXE Node.js SDK provides a simple and powerful way to integrate vehicle data into your JavaScript and TypeScript applications. This guide will help you get started quickly.
For more information, see the package on npm.
Installation
Install the CarsXE Node.js package using npm or yarn:
npm install carsxe-api
or
yarn add carsxe-api
Setup
First, import the CarsXE client and initialize it with your API key:
decode.js
const { CarsXE } = require("carsxe-api");
// Initialize the client
const carsxe = new CarsXE("YOUR_API_KEY_HERE");
For TypeScript:
decode.ts
import { CarsXE } from "carsxe-api";
const carsxe = new CarsXE("YOUR_API_KEY_HERE");
Basic Usage
VIN Specifications
decode.js
const vin = 'WBAFR7C57CC811956';
carsxe
.specs({ vin })
.then((vehicle) => console.log(vehicle.input.vin))
.catch((error) => console.error(error));
Or using async/await:
decode.js
async function decodeVIN() {
try {
const vehicle = await carsxe.specs({
vin: 'WBAFR7C57CC811956'
});
console.log(vehicle.input.vin);
} catch (error) {
console.error("Error:", error);
}
}
decodeVIN();
International VIN Decoder
decode.js
async function decodeInternationalVIN() {
try {
const intVin = await carsxe.internationalVinDecoder({
vin: 'WF0MXXGBWM8R43240'
});
console.log(intVin);
} catch (error) {
console.error("Error:", error);
}
}
Market Value
decode.js
async function getMarketValue() {
try {
const value = await carsxe.marketvalue({
vin: 'WBAFR7C57CC811956'
});
console.log(value);
} catch (error) {
console.error("Error:", error);
}
}
Vehicle History
decode.js
async function getVehicleHistory() {
try {
const history = await carsxe.history({
vin: 'WBAFR7C57CC811956'
});
console.log(history);
} catch (error) {
console.error("Error:", error);
}
}
License Plate Decoder
decode.js
async function decodePlate() {
try {
const plate = await carsxe.platedecoder({
plate: '7XER187',
state: 'CA',
country: 'US'
});
console.log(plate);
} catch (error) {
console.error("Error:", error);
}
}
Vehicle Images
decode.js
async function getVehicleImages() {
try {
const imgs = await carsxe.images({
make: 'BMW',
model: 'X5',
year: '2019'
});
console.log(imgs);
} catch (error) {
console.error("Error:", error);
}
}
Vehicle Recalls
decode.js
async function checkRecalls() {
try {
const recalls = await carsxe.recalls({
vin: '1C4JJXR64PW696340'
});
console.log(recalls);
} catch (error) {
console.error("Error:", error);
}
}
Plate Image Recognition
decode.js
async function recognizePlateFromImage() {
try {
const plateImg = await carsxe.plateImageRecognition({
imageUrl: 'https://api.carsxe.com/img/apis/plate_recognition.JPG'
});
console.log(plateImg);
} catch (error) {
console.error("Error:", error);
}
}
VIN OCR from Image
decode.js
async function extractVINFromImage() {
try {
const vinOcr = await carsxe.vinOcr({
imageUrl: 'https://user-images.githubusercontent.com/5663423/30922082-64edb4fa-a3a8-11e7-873e-3fbcdce8ea3a.png'
});
console.log(vinOcr);
} catch (error) {
console.error("Error:", error);
}
}
Year-Make-Model Search
decode.js
async function searchByYearMakeModel() {
try {
const ymm = await carsxe.yearMakeModel({
year: '2023',
make: 'Toyota',
model: 'Camry'
});
console.log(ymm);
} catch (error) {
console.error("Error:", error);
}
}
OBD Code Decoder
decode.js
async function decodeOBDCode() {
try {
const obd = await carsxe.obdcodesdecoder({
code: 'P0115'
});
console.log(obd);
} catch (error) {
console.error("Error:", error);
}
}
Error Handling
The SDK provides comprehensive error handling:
error-handling.js
async function handleErrors() {
try {
const result = await carsxe.specs({
vin: "INVALID_VIN"
});
} catch (error) {
if (error.status === 400) {
console.log("Invalid VIN format");
} else if (error.status === 401) {
console.log("Invalid API key");
} else if (error.status === 429) {
console.log("Rate limit exceeded");
} else {
console.log("Unexpected error:", error.message);
}
}
}
Environment Variables
Store your API key securely using environment variables:
.env
# .env file
CARSXE_API_KEY=your_api_key_here
app.js
require("dotenv").config();
const carsxe = new CarsXE(process.env.CARSXE_API_KEY);
Available Endpoints
Method | Description |
---|---|
carsxe.specs({ vin }) | Decode VIN & get full vehicle specifications |
carsxe.internationalVinDecoder({ vin }) | Decode VIN with worldwide support |
carsxe.platedecoder({ plate, state, country }) | Decode license plate info |
carsxe.marketvalue({ vin }) | Estimate vehicle market value based on VIN |
carsxe.history({ vin }) | Retrieve vehicle history (ownership, accidents, etc.) |
carsxe.images({ make, model, year }) | Fetch images by make, model, year, trim |
carsxe.recalls({ vin }) | Get safety recall data for a VIN |
carsxe.plateImageRecognition({ imageUrl }) | Read & decode plates from images |
carsxe.vinOcr({ imageUrl }) | Extract VINs from images using OCR |
carsxe.yearMakeModel({ year, make, model }) | Query vehicle by year, make, model and trim |
carsxe.obdcodesdecoder({ code }) | Decode OBD error/diagnostic codes |
Start building powerful automotive applications with CarsXE's Node.js SDK!