I created this simple console application to consume data from an API, I am looking for a way in which the previous contents on a user console will be cleared any time the program is run. I thought clear()
should do that but it doesn't seem to be working. Any help on how to do this
'use strict';
var request = require('request'),
clear = require('clear'),
figlet = require('figlet'),
inquirer = require('inquirer'),
chalk = require('chalk'),
Spinner = require('clui').Spinner;
clear();
console.log(
chalk.cyan(
figlet.textSync('Welcome!', { horizontalLayout: 'left' })
)
);
function getIpadd () {
var status = new Spinner('Getting your IP, please wait...');
status.start();
//Request the IP address
request('https://api.ipify.org?format=json', function (err, res, data){
if (err) {
console.log(err)
return;
}
data = JSON.parse(data);
status.stop();
console.log('\nYour IP is: ' + data.ip + '\n');
exitApp();
});
}
function startApp() {
inquirer.prompt([ {
type: 'list',
name: 'option',
message: 'Press enter to Check Ip address',
choices: [
'Check my Ip address',
]
} ]).then(function (answer) {
if(answer.option === 'Check my Ip address'){
getIpadd();
};
});
}
//Function that Exits the app
function exitApp() {
inquirer.prompt([ {
type: 'list',
name: 'option',
message: 'Exit?',
choices: [
'Yes',
'No',
]
} ]).then(function (answer) {
if(answer.option === 'No') return startApp();
if(answer.option === 'Yes') return console.log(chalk.yellow('=============Thanks for using this app!============='));
});
}
startApp();