Skip to content

Instantly share code, notes, and snippets.

@hugomd
Created May 23, 2018 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugomd/61bf21ea84172855f006484f7181b5e0 to your computer and use it in GitHub Desktop.
Save hugomd/61bf21ea84172855f006484f7181b5e0 to your computer and use it in GitHub Desktop.
const main = async () => {
try {
// Initialise prompt with an empty message
prompt.start();
prompt.message = '';
// Turn prompt.get() into a promise
const get = util.promisify(prompt.get);
// Create a schema to validate user input
const usernameSchema = [
{
description: 'Enter your username',
name: 'username',
message: 'Username must be only letters, numbers, or dashes',
required: true,
},
];
// Ask the user for their username and assign it to a variable
const {username} = await get(usernameSchema);
+ await createUser(username);
} catch (err) {
console.log(`Failed with ${err}`);
process.exit(1);
}
});
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment