Skip to content
Permalink
Browse files
fixed text input issue
  • Loading branch information
aa7401 committed Oct 11, 2019
1 parent 64be017 commit 87c1585d8dc97aa72724570a00de5e39e18f5365
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
@@ -2,6 +2,8 @@
'use strict'

const request = require('request')
const readline = require('readline')

const baseURL = 'https://api.exchangeratesapi.io/latest'

async function main() {
@@ -10,17 +12,21 @@ async function main() {
await checkValidCurrencyCode(base)
const data = await getData(`${baseURL}?base=${base}`)
await printObject(data)
const to = await getInput('convert to')
console.log(to)
process.exit()
} catch (err) {
console.log(`error: ${err.message}`)
}
}

const getInput = prompt => new Promise( (resolve) => {
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdout.write(`${prompt}: `)
process.stdin.on('data', text => resolve(text))
const getInput = prompt => new Promise(resolve => {
const read = readline.createInterface({ input: process.stdin, output: process.stdout })
read.question(`${prompt}: `, value => {
console.log(`You entered ${value}`)
read.close()
resolve(value)
})
})

const checkValidCurrencyCode = code => new Promise( (resolve, reject) => {
@@ -34,6 +34,7 @@
"koa-static": "^5.0.0",
"koa-views": "^6.1.5",
"mime-types": "^2.1.22",
"readline": "^1.3.0",
"readline-sync": "^1.4.10",
"request": "^2.88.0",
"sqlite-async": "^1.0.11"
@@ -2,13 +2,17 @@
'use strict'

const request = require('request')
const readline = require('readline')

const baseURL = 'https://api.exchangeratesapi.io/latest'

const getInput = prompt => new Promise( (resolve) => {
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdout.write(`${prompt}: `)
process.stdin.on('data', text => resolve(text))
const getInput = prompt => new Promise(resolve => {
const read = readline.createInterface({ input: process.stdin, output: process.stdout })
read.question(`${prompt}: `, value => {
console.log(`You entered ${value}`)
read.close()
resolve(value)
})
})

const checkValidCurrencyCode = code => new Promise( (resolve, reject) => {

0 comments on commit 87c1585

Please sign in to comment.