Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created June 4, 2019 14:46
Show Gist options
  • Select an option

  • Save codebubb/0f38dadccdd6b3b18d270d3d8851bfb4 to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/0f38dadccdd6b3b18d270d3d8851bfb4 to your computer and use it in GitHub Desktop.
node mod collection
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