RunKit + npm: vin-generator

node v10.21.0
version: 1.0.0
endpointsharetweet
var vinGenerator = require("vin-generator") var decoder = require("vin-decode").default var vinValidator = require('vin-validator'); var express = require("@runkit/runkit/express-endpoint/1.0.0"); var app = express(exports); var request = require('request') var _ = require("lodash") app.get("/", async (req, res) => { var randomVin = vinGenerator.generateVin(); let excludeFromChanges = ["BMW", "FIAT", "GMC", "RAM", "MINI", "MG", "SRT"] while (!vinValidator.validate(randomVin)) { randomVin = vinGenerator.generateVin(); } var result = await decoder(randomVin).decode() request(`https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVin/${randomVin}?format=json`, (e,r,b) => { let out = JSON.parse(b); let data = {}; out.Results.forEach(res => { data[_.camelCase(res.Variable)] = res.Value }) if (!excludeFromChanges.includes(data.make)) { data.make = _.startCase(_.toLower(data.make)); } res.send(` <h1>Car Info</h1> <p>${data.errorCode}</p> <p>${data.errorText}</p> <div> <p>${randomVin}</p> <p>${data.make} ${data.model} ${data.modelYear}</p> <a href="https://www.tirerack.com/tires/TireSearchResults.jsp?tireIndex=0&autoMake=${data.make}&autoYear=${data.modelYear}&autoModel=${data.model.replace(' ', '+')}">Tire Rack</a> <p>${JSON.stringify(data)}</p> </div> `) }) }) app.get('/tire',async (req,res) => { })
Created from: https://npm.runkit.com/vin-generator
Loading…

no comments

    sign in to comment