Created
May 24, 2020 14:38
-
-
Save aakashlpin/3bcc701c1efcfb6e7619f135f21888a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inquirer = require('inquirer'); | |
var fetch = require('isomorphic-unfetch'); | |
console.log('👋🏽 Saturday Hacks! Enter details to reserve your spot:'); | |
inquirer | |
.prompt([ | |
{ | |
type: 'input', | |
name: 'name', | |
message: 'Hey there! Enter your name:', | |
default: 'John Doe' | |
}, | |
{ | |
type: 'input', | |
name: 'emailid', | |
message: 'And now your Email id:', | |
default: '[email protected]' | |
}, | |
]) | |
.then(answers => { | |
// Use user feedback for... whatever!! | |
console.log(JSON.stringify(answers, null, ' ')); | |
fetch('https://api.emailapi.io/box_f09c124ecade935991f6/users', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({answers}) | |
}).then( r => { | |
// console.log(r.headers.get('location')); | |
console.log('You\'ve successfully reserved your spot!'); | |
return r.json(); | |
}) | |
}) | |
.catch(error => { | |
if(error.isTtyError) { | |
// Prompt couldn't be rendered in the current environment | |
} else { | |
// Something else when wrong | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "saturday-hacks-registration", | |
"version": "0.0.0", | |
"bin": "./index.js", | |
"dependencies": { | |
"inquirer": "^7.1.0", | |
"isomorphic-unfetch": "^3.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment