-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The npm inquirer package offers some nice prompts for filling out more complex data (e.g. radio buttons, multi-selects) and then writing the output to a file. This might be a nice feature (or possibly its own package).
Example:
const fs = require('fs');
const inquirer = require('inquirer');
// Prompt the user
inquirer
.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?'
},
{
type: 'list',
message: 'What is your preferred method of communication?',
name: 'contact',
choices: ['email', 'phone', 'Slack', 'smoke signal']
},
{
type: 'checkbox',
message: 'What languages do you know?',
name: 'stack',
choices: ['HTML', 'CSS', 'JavaScript', 'SQL']
}
]) // Write the user response to a file by chaining the below callback method to the prompt above.
.then(function(data) {
// Bonus: Generate the name of your user file from their input
const filename =
data.name
.toLowerCase()
.split(' ')
.join('') + '.json';
fs.writeFile(filename, JSON.stringify(data, null, '\t'), function(err) {
if (err) {
return console.log(err);
}
console.log('Success!');
});
});
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request