I'm trying to use the command node index.js within the terminal to bring up the prompts I made and keep running into several errors, I looked them up on here seemingly fixed it and got another error. Maybe someone can point it out so I can save some time hopefully.. If you need more code details let me know.
Here is the ERROR in the terminal
$ node index.js
file:///C:/Users/Owner/bootcamp/homework/10-team-profile-generator/index.js:2
const fs = require('fs');
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Users\Owner\bootcamp\homework\10-team-profile-generator\package.json'
contains "type": "module". To treat it as a CommonJS
script, rename it to use the '.cjs' file extension.
at ←[90mfile:///C:/Users/Owner/bootcamp/homework/10-team-profile-generator/←[39mindex.js:2:12
←[90m at ModuleJob.run (node:internal/modules/esm/module_job:193:25)←[39m
at async Promise.all (index 0)
←[90m at async ESMLoader.import (node:internal/modules/esm/loader:533:24)←[39m
←[90m at async loadESM (node:internal/process/esm_loader:91:5)←[39m
←[90m at async handleMainPromise (node:internal/modules/run_main:65:12)←[39m
INDEX.JS
// node modules
const fs = require('fs');
const inquirer = require('inquirer')
const generateTeam = require("./src/template.js");
// lib modules
const Engineer = require("./lib/employee");
const Intern = require("./lib/intern");
const Manager = require("./lib/manager");
// Array for answers to questions
const newStaffMemberData = [];
// Array object questions asked in CLI to user
const questions = async () => {
const answers = await inquirer
.prompt([
{
type: "input",
message: "What is your name?",
name: "name",
},
{
type: "input",
message: "What is your ID number?",
name: "id",
},
{
type: "input",
message: "What is your email?",
name: "email",
},
{
type: "list",
message: "What is your role?",
name: "role",
choices: ["Engineer", "Intern", "Manager"],
},
])
// console.log(answers);
// if manager selected, answer these specific question
if (answers.role === "Manager") {
const managerAns = await inquirer
.prompt([
{
type: "input",
message: "What is your office number",
name: "officeNumber",
},
])
const newManager = new Manager(
answers.name,
answers.id,
answers.email,
managerAns.officeNo
);
newStaffMemberData.push(newManager);
// if engineer selected answer these set of questions
} else if (answers.role === "Engineer") {
const githubAns = await inquirer
.prompt([
{
type: "input",
message: "What is your GitHub user name?",
name: "github",
}
])
const newEngineer = new Engineer(
answers.name,
answers.id,
answers.email,
githubAns.github
);
newStaffMemberData.push(newEngineer);
// if intern selected answer these set of questions
} else if (answers.role === "Intern") {
const internAns = await inquirer
.prompt([
{
type: "input",
message: "What university did you attend?",
name: "school",
},
])
const newIntern = new Intern(
answers.name,
answers.id,
answers.email,
internAns.school
);
newStaffMemberData.push(newIntern);
}
}; //end of questions function
async function promptQuestions() {
await questions()
const addMemberAns = await inquirer
.prompt([
{
name:'addMember',
type: 'list',
choices: ['Add a new member', 'Create team'],
message: "What would you like to do next?"
}
])
if (addMemberAns.addMember === 'Add a new member') {
return promptQuestions()
}
return createTeam();
}
promptQuestions();
function createTeam () {
console.log("new guy", newStaffMemberData)
fs.writeFileSync(
"./output/index.html",
generateTeam(newStaffMemberData),
"utf-8"
);
}