Norse Power Metal

    r4nasa-api

    1.0.5 • Public • Published

    r4nasa-api -Get space data easy

    alt text

    [Github [npm downloads [GitHub

    npm package

    NPM Version node js-standard-style [version [use

    In development.

    Installation

    just type this to install the module

    $ npm install r4nasa-api

    this module has dependencies so it works only if fs and https are installed also this module has a function that retuns the data you requested in a json file called requested_data.json

    $ npm install https
    $ npm install file system

    Example

    at top add the two constants for r4nasa and fs

    const r4nasa = require('r4nasa-api')
    const fs = require('fs');

    then add the line

    const R4nasa = new r4nasa({token:'YOUR_TOKEN'});

    replace YOUR_TOKEN with your registration token where you can found it Here

    Random Mars images by sol

    to get thousands random Mars images by random rovers you have to request data with a function that returns 1 image and some data type

    R4nasa.RequestMars_sol(rover, sol)

    in the two parameters you have to add the rover name(Curiosity is the rover with more data) and a random sol

    this will create and write data in a json filed called requested_data.json

    {
    "img":"http://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01344/opgs/edr/fcam/FRB_516810721EDR_F0541238FHAZ00304M_.JPG",
    "sol":1344,
    "rover":"Curiosity",
    "date":"2016-05-17"
    }

    and then in your script you have to parse the data with fs module that you have installed

    //don't change requested_data.json path!
    let rawdata = fs.readFileSync('./requested_data.json');  
    var json = JSON.parse(rawdata)
    //here are you going to get the img value in the json file 
    console.log(json.img)

    the final script will looks like

    const r4nasa = require('r4nasa-api')
    const fs = require('fs');
    const R4nasa = new r4nasa({token:'YOUR_TOKEN'});
     
    //this is the parse function that will be parse the data in the json file
    function parse()
    {
    let rawdata = fs.readFileSync('./requested_data.json');  
    var json = JSON.parse(rawdata)
    //here are you going to get the img value in the json file
    console.log(json.img)
    }
     
    //this is a random number for a random sol
    var randomSOL = Math.floor(Math.random() * 2394);
     
    // writing and creating the file with data
    R4nasa.RequestMars_sol("Curiosity", randomSOL)
    // generating data requires time, and if the parse function is called before RequestMars_sol finish this will return an error 
    setTimeout(parse, 3800);
     

    the module is still in development so it doesn't have all the functions

    Install

    npm i r4nasa-api

    DownloadsWeekly Downloads

    0

    Version

    1.0.5

    License

    ISC

    Unpacked Size

    12.9 kB

    Total Files

    4

    Last publish

    Collaborators

    • r4yan