Work with a partner to implement the following user story:
It’s done when I have initialized my repository with a package.json
file by running npm init -y
.
It’s done when I have installed inquirer and added it to my list of dependencies by running npm i inquirer --save
.
It’s done when the application asks the user, “What is your name?”
It’s done when the application asks the user, “What languages do you know?”
It’s done when the application asks the user, βWhat is your preferred method of communication?”
It’s done after I have written those responses to a file.
Why do we need to use JSON.stringify
? How can we use the npm page for inquirer
to see how to use checkboxes and lists?
If you have completed this activity, work through the following challenge with your partner to further your knowledge:
Use Google or another search engine to research this.
{
"name": "Solved",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"inquirer": "^6.5.0"
}
}
const inquirer = require('inquirer');
const fs = require('fs');
inquirer
.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?',
},
{
type: 'checkbox',
message: 'What languages do you know?',
name: 'stack',
choices: ['HTML', 'CSS', 'JavaScript', 'MySQL'],
},
{
type: 'list',
message: 'What is your preferred method of communication?',
name: 'contact',
choices: ['email', 'phone', 'telekinesis'],
},
])
.then((data) => {
const filename = `${data.name.toLowerCase().split(' ').join('')}.json`;
fs.writeFile(filename, JSON.stringify(data, null, '\t'), (err) =>
err ? console.log(err) : console.log('Success!')
);
});