var fs = require('fs');
const yaml = require('js-yaml');
const settings = yaml.load(fs.readFileSync('../settings.yml', 'utf8'));
const {car} = require('./car-bmw.js');
function log() {
console.log("Car name:" + settings.space + car.name);
console.log("Car model:" + settings.space + car.model);
console.log("Car color:" + settings.space + car.color);
};
try {
log();
} catch (error) {
console.log(`${settings.errorMessage}`);
console.error(error);
}[e][1]
When I try to run this script, I get the error Uncaught Error: ENOENT: no such file or directory, open './settings.yml' and Process exited with code 1 . Anybody can help?
The path is incorrect in the filesync, you can use path.join
var fs = require('fs');
const yaml = require('js-yaml');
const path = require('path');
// file will be picked up if it is in same directory
// else you need to provide the relative path and path.join will
// create a correct path for it
const settings = yaml.load(fs.readFileSync(path.join(__dirname, '/settings.yml'), 'utf8'));
const {car} = require('./car-bmw.js');
function log() {
console.log("Car name:" + settings.space + car.name);
console.log("Car model:" + settings.space + car.model);
console.log("Car color:" + settings.space + car.color);
};
try {
log();
} catch (error) {
console.log(`${settings.errorMessage}`);
console.error(error);
}[e][1]