-
Notifications
You must be signed in to change notification settings - Fork 3
/
database.js
36 lines (31 loc) · 950 Bytes
/
database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var fs = require( 'fs' );
var faker = require( 'faker' );
var colors = require( 'colors' );
// dynamically create JSON of 100 stations
var stations = [];
for ( var i = 1; i <= 100; i++ ) {
var station = {
id: i,
locationName: faker.random.words(),
city: faker.address.city()
};
if ( i % 20 === 0 ) {
station.broken = true;
} else {
station.broken = false;
}
stations.push( station );
}
// save to database.json
try {
fs.writeFile( 'database.json', JSON.stringify( stations ), function( error ) {
if ( error ) {
throw new Error( error );
} else {
// output success
console.log( 'Successfully created database.json for fake database.'.green );
}
});
} catch ( error ) {
console.log( colors.red( 'There was an error creating a fake database file. Please log an issue or pull request at https://github.com/Volta-Charging/Code-Challenge/issues. Error: \n\n' + error.message ) );
}