Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

API in Node

Hi, I have an api and would like to update its query parameter to any country name form command line, how can I do this? I have looked up node documentation but could not make it work.

API = https://restcountries.eu/rest/v2/name/{name}?fullText=true

Thanks

1 Answer

Steven Parker
Steven Parker
229,786 Points

Command line arguments are available from the "process.argv" array. For example, this will output your URL with the name of each argument plugged in:

args = process.argv.slice(2);    // skip "node" and the name of this program
for (name of args) {             // build URLs from the rest
    url = `https://restcountries.eu/rest/v2/name/${name}?fullText=true`;
    console.log(url);
}