Coder Social home page Coder Social logo

weather-maps-sample's Introduction

Practical NodeJS an Express


2 Endpoint API Connect With one request (Weather and MapBox)

  • Description :
    • the weather app use API from MapBox and Weather
    • How to cycle method ??
    • first,. we take information about location from mapbox.. so mapbox can find the location and show the information
    • second,. from information obtained from the mapbox, we made some function to retrive the information.
    • third, and send information about location (name of location, Longitude and Latitude so on..) and then bring the information to weather stack to get the weather data for the location.
    • fourth, the weather stack can show u.. information about the location that has been taken from mapbox.

  • Source API (Register to get token)

  • Module Installed

    • express
    • request
    • hbs
    • nodemon ( -global )
  • UI (Template)

  • Practical

    • Callback Function VS Arrow Function
    • Assign Arrow Function to Callback Function
    • Use the Parameter and Data in arrow Function
    • Undestand I/O Bloking and NonBlocking Code
    • Use NonBlocking Code to Arrow Function
    • Call Endpoin API with Module request (npm i install request)
    • Call Endpoint API with fetch
    • Assign endpoint with Fetch to Arrow Function
  • How to Use this project?

    • clone this Repo

        https://github.com/Ekhel/Weather-Maps-Sample.git
      
    • Node Initialize

      npm install
    • Change ACCESS_TOKEN from path : /src/utils/geocode.js (from Mapbox Account)

          const geocode = (address, callback) => {
          const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/'+ address + '.json?access_token=pk.ACCESS_TOKEN&limit=1';
      
          request({ url, json: true }, (error, { body }) => {
              if (error) {
                  callback('Unable to connect to location services!', undefined)
              } else if (body.features.length === 0) {
                  callback('Unable to find location. Try another search.', undefined)
              } else {
                  callback(undefined, {
                      latitude: body.features[0].center[1],
                      longitude: body.features[0].center[0],
                      location: body.features[0].place_name
                  })
              }
          })
      }
    • Change YOUR_ACCESS_KEY from path: /src/utils/forecast.js (from weather account)

          const forecast = (latitude, longitude, callback) => {
          const url = 'http://api.weatherstack.com/current?access_key=YOUR_ACCESS_KEY&query=' + latitude + ',' + longitude
      
          request({ url, json: true }, (error, { body }) => {
              if (error){
                  callback('Unable to connect to weather service!', undefined)
              } else if (body.error) {
                  callback('Unable to find location', undefined)
              } else {
                  callback(undefined, 'Weather today ' + body.current.weather_descriptions[0] + ' Temp Right now ' + body.current.temperature + ' C')
              }
          })
      }

weather-maps-sample's People

Contributors

ekhel 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.