-
Notifications
You must be signed in to change notification settings - Fork 1
/
populate.js
29 lines (25 loc) · 916 Bytes
/
populate.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
import { readFile } from 'fs/promises';
import dotenv from 'dotenv';
dotenv.config();
import connectDB from './db/connect.js';
import Job from './models/Job.js';
async function populate(){
try{
console.log("======== Populate() ========");
await connectDB(process.env.MONGO_URL);
console.log("---- Finished connecting to database ---- ");
console.log("---- Start to Read and Parse the json file ---- ");
const jsonProducts = JSON.parse(
await readFile(new URL('./MOCK_DATA.json', import.meta.url))
);
console.log("---- Read and parsed the data from MOCK_DATA.json ---- ");
console.log(`The value of "jsonProducts" is: ${jsonProducts}`);
await Job.create(jsonProducts);
console.log("---- Job Created Successfully! ----");
} catch(error){
console.log(`Error occured in populate: ${error}`);
console.log(error.message);
process.exit(1);
}
}
populate();