GithubHelp home page GithubHelp logo

andrewjbateman / nodejs-api-data Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 518 KB

:clipboard: Node.js app to display data from a cryptocurrency API. Tutorial code updated to latest ES6

JavaScript 99.27% Shell 0.73%
nodejs commander colors axios-rest json-api cryptocoins configstore inquirer javascript cryptocurrency

nodejs-api-data's Introduction

โšก Node.js API Data

  • Node.js Command Line Interface (CLI) app that takes an API key user input and outputs nomics cryptocurrency API data. Tutorial code (see 'Inspiration' below) updated to use ES6 module imports etc.
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

๐Ÿ“„ Table of contents

๐Ÿ“š General info

  • Postman used to test API using a simple GET request
  • node.js bin field used as executable file - maps command name to local file name. Important: file referenced in bin; ./bin/coindex.js starts with #!/usr/bin/env node, otherwise the scripts are started without the node executable!
  • coindex.js is the first file executed. This calls the files in the commands folder. The key.js file calls the lib class KeyManager which includes key set, view and delete functions. It also calls the utils const isRequired. The check.js file calls the lib classes KeyManager and CryptoAPI and uses axios to make a http call to the nomics cryptocurrency API.

๐Ÿ“ท Screenshots

postman screenshot nodejs screenshot

๐Ÿ“ถ Technologies

๐Ÿ’พ Setup

  • Install dependencies using npm i
  • Create .env file
  • See .env.example then add a default 32-character key from nomics cryptocurrency API
  • Type npm link to make all commands work from any CLI directory
  • Get yourself a 32-character key from nomics cryptocurrency API
  • type nodejs-api-data to get top level commands list; key to manage API key, check to see crypto currency prices and help
  • type nodejs-api-data key to get API key commands list; set to add 32-character key, show to see API key and remove to delete the key
  • type nodejs-api-data key -h to get full list of key help commands
  • type nodejs-api-data key setto get add key prompt. Enter the key obtained from nomics cryptocurrency API
  • type nodejs-api-data key showto display the API key
  • type nodejs-api-data key deleteto delete the API key
  • type nodejs-api-data check priceto see list of crypto currency prices.
  • type nodejs-api-data check price --coin=BTC to see price and rank of BTC crypto (comma separated coin names (with NO spaces) used by API GET request - note: putting a coin name of ' ' (empty space) will return a list of ALL 2709 cryto coins!)

๐Ÿ’ป Code Examples

  • key.js function to set API key from user input. Note: I replaced the isRequired utility to use my own key from the .env file as default if no other key is set. I also added a check of the input string to ensure it is 12 characters long and only contains letters or numbers. Keys are now 32 characters long.
async set() {
  const keyManager = new KeyManager();
  const input = await inquirer.prompt([
    {
      type: "input",
      name: "key",
      message: "Enter API key obtained from https://nomics.com or press ENTER to use default API key. ".green
    },
  ]);

  // If user enters an empty string my default API key from the .env file is used
  if (input.key === "") {
    const key = keyManager.setKey(process.env.API_key);
    console.log("default API key used".blue);
    return key;
  }

  // check if user inputs a key that is alphanumeric & 32 characters long
  else if (input.key.length === 32 && input.key.match(alphaNumeric)) {
    const key = keyManager.setKey(input.key);
    console.log("API key set".blue);
    return key;
  }

  // user to input key again if the input key was not an empty string or it was not 32 characters long
  console.log("API key should be alphanumeric and 32 characters long. ".red + "Try again.".blue);
  return;
},

๐Ÿ†’ Features

  • npm link command used to make all commands work from any CLI directory

๐Ÿ“‹ Status & To-Do List

  • Status: Working
  • To-Do: Nothing

๐Ÿ‘ Inspiration

๐Ÿ“ License

  • N/A.

โœ‰๏ธ Contact

nodejs-api-data's People

Contributors

andrewjbateman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.