Created
June 4, 2019 14:46
-
-
Save codebubb/0f38dadccdd6b3b18d270d3d8851bfb4 to your computer and use it in GitHub Desktop.
node mod collection
This file contains hidden or 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
| const axios = require('axios'); | |
| const chalk = require('chalk'); | |
| const commander = require('commander'); | |
| commander | |
| .version('1.0.0') | |
| .option('-t --type <type>', 'Lookup type') | |
| .option('-n --number <number>', 'Number of results') | |
| .parse(process.argv); | |
| axios.post(`https://swapi.co/api/${commander.type}/${commander.number}`) | |
| .then(results => { | |
| console.log(results); // Use .data for just results | |
| }) | |
| .catch(error => { | |
| console.log(chalk.red.bold('Error sending request')); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment