Error: ENOENT: no such file or directory, open

https://nettle-minibus.glitch.me

So I am trying to convert CSV to JSON using the package convert-csv-to-json. I have added the CSV to my assets for the project. I copied the URL to the node code. But I get this error

Error: ENOENT: no such file or directory, open

I am not sure why since I have done the same with a JS file and referenced it in the SRC and it worked.

fs.readFile only reads local paths. You want to either put the file locally, or request it first.

Do you mean locally like this: (__dirname + ‘/views/index.html’)?

I have loaded the file to the assets to my project so thought I could read it from there? That when i am getting this error. I have taken that URL for the JSON file and put it into a browser and the JSON file is displayed.

I have loaded a JS file to be used in my HTML page for script and it brings it in from the ASSETS just fine.

So going forward on this test project - I need to be able to read a JSON file from an external server. I guess similar to what I am trying to do here - read the file using the URL for the fie on the Glitch server. This JSON file will be replace once a day on an external server.

Yes, exactly.

Assets in your Glitch project isn’t a local directory, in fact isn’t a folder at all - it just lists files associated with your project on the cdn.

There are a couple of methods to achieve what you want:


Thanks Gareth. Got the JSON file in using the second option - must be to big to send to console cutting off data. So I made a smaller JSON file - 2 array entries so I could get it working.

I use this to read it in:

var request = require(‘request’);
request.get(‘https://cdn.glitch.com/e11bb4a0-863b-4fbf-b8a9-cfed70b9f814%2FTwoVehicles.json?1529990938888’, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
[
{
“DealerID”: 16424634,
“VIN”: “1FDUF5HT1HEB8888888”,
“StockNumber”: “T9501”,
“Status”: “A”,
“VehicleType”: 0,
“Year”: 2017,
“Make”: “Ford”,
“Model”: “F-550”,
“Trim”: “XL”,
“Body”: “Dump Body”,
“VehicleClass”: “Passenger”,
“VehicleCategory”: “Retail”,
“Mileage”: 142,
“Transmission”: “Automatic”,
“EngineDisplacement”: 6.7,
“EngineSize”: “8 Cylinder”,
“Induction”: “Diesel”,
“DriveTrain”: “”,
“FuelType”: “”,
“FuelEconomyCity”: 0,
“FuelEconomyHighway”: 0,
“FuelEconomyCombined”: 0,
“Doors”: 0,
“OEMColorCodeExterior”: “”,
“OEMColorCodeInterior”: “”,
“OEMColorNameExterior”: “White”,
“OEMColorNameInterior”: “”,
“GenericColorExterior”: “White”,
“GenericColorInterior”: “Gray”,
“InternetPrice”: 0,
“ComparisonPrice”: 0,
“WholeSalePrice”: “”,
“MSRP”: 0,
“InternetSpecial”: “N”,
“OemModelCode”: “”,
“HasWarranty”: “Y”,
“CertificationWarranty”: 191,
“WarrantyMonth”: 0,
“WarrantyMiles”: 0,
“CertificationNumber”: “”,
“ServiceContract”: “N”,
“InServiceDate”: “1/1/1900 0:00”,
“CertificationDate”: “1/1/1900 0:00”,
“DateManufactured”: “8/1/2016 0:00”,
“DateCreated”: “1/16/2017 16:31”,
“DateUpdated”: “5/17/2018 17:21”,
“DateRemoved”: “1/1/1900 0:00”,
“DatePhotosUpdated”: “1/16/2017 16:36”,
“Photos”: 10,
“SuperSizePhotos”: 10,
“AddendumDetails”: “”,
“Options”: “”,
“PurchasePayment”: 0,
“PurchaseDownPayment”: 0,
“PurchaseTerm”: 0,
“PurchaseDisclosure”: “”,
“PurchaseRate”: 0,
“LeasePayment”: 0,
“LeaseDownPayment”: 0,
“LeaseTerm”: 0,
“LeaseDisclosure”: “”,
“LeaseRate”: 0,
“LeaseResidual”: 0,
“Invoice”: 0,
“ACV”: 0,
“Special”: 0,
“Discount”: 0,
“OptionCodes”: “”,
“PackageCodes”: “”
},
{
“DealerID”: 21641255,
“VIN”: “1FDTF4GT7HEB66666”,
“StockNumber”: “T9626”,
“Status”: “A”,
“VehicleType”: 0,
“Year”: 2017,
“Make”: “Ford”,
“Model”: “F-450”,
“Trim”: “XL”,
“Body”: “Cab & Chassis”,
“VehicleClass”: “Passenger”,
“VehicleCategory”: “Retail”,
“Mileage”: 0,
“Transmission”: “Automatic”,
“EngineDisplacement”: 6.7,
“EngineSize”: “8 Cylinder”,
“Induction”: “Turbo Diesel”,
“DriveTrain”: “”,
“FuelType”: “”,
“FuelEconomyCity”: 0,
“FuelEconomyHighway”: 0,
“FuelEconomyCombined”: 0,
“Doors”: 0,
“OEMColorCodeExterior”: “”,
“OEMColorCodeInterior”: “”,
“OEMColorNameExterior”: “White”,
“OEMColorNameInterior”: “”,
“GenericColorExterior”: “White”,
“GenericColorInterior”: “Gray”,
“InternetPrice”: 0,
“ComparisonPrice”: 0,
“WholeSalePrice”: “”,
“MSRP”: 0,
“InternetSpecial”: “N”,
“OemModelCode”: “”,
“HasWarranty”: “Y”,
“CertificationWarranty”: 191,
“WarrantyMonth”: 0,
“WarrantyMiles”: 0,
“CertificationNumber”: “”,
“ServiceContract”: “N”,
“InServiceDate”: “1/1/1900 0:00”,
“CertificationDate”: “1/1/1900 0:00”,
“DateManufactured”: “8/1/2016 0:00”,
“DateCreated”: “1/16/2017 16:31”,
“DateUpdated”: “5/10/2018 17:21”,
“DateRemoved”: “1/1/1900 0:00”,
“DatePhotosUpdated”: “1/16/2017 16:35”,
“Photos”: 10,
“SuperSizePhotos”: 10,
“AddendumDetails”: “”,
“Options”: “”,
“PurchasePayment”: 0,
“PurchaseDownPayment”: 0,
“PurchaseTerm”: 0,
“PurchaseDisclosure”: “”,
“PurchaseRate”: 0,
“LeasePayment”: 0,
“LeaseDownPayment”: 0,
“LeaseTerm”: 0,
“LeaseDisclosure”: “”,
“LeaseRate”: 0,
“LeaseResidual”: 0,
“Invoice”: 0,
“ACV”: 0,
“Special”: 0,
“Discount”: 0,
“OptionCodes”: “”,
“PackageCodes”: “”
}
]

So no matter what I do to access this data it will not return the value. I have tried

body[0].VIN - cannot find it

I have used array handling like this:

for (var i = 0; i < body.length; i++) {
console.log(body[i].VIN);
}

Nothing lets me get to the VIN text. Do I need to do something with BODY first?

I have 2 JSON files I will need to bring in - I need to take the VIN from set of JSON to find entries for that VIN in another JSON file with image links in.

Help is appreciated.

@Jeff after reading in the file, it is a string, you can get it into a javascript object with

var allVehicles = JSON.parse(body)
console.log(allVehicles[0].DealerID)

Hopefully you don’t run out of memory with the big file. If you do, you could read in chunks and use a module like Oboe to process individual vehicles as they are read.

2 Likes

Thanks for the help! That helped!