Giter VIP home page Giter VIP logo

node-movie-api's Introduction

node-movie-api

practice repo to get api key for TMDb

setup

  1. Go to the main directory and run this command to get all the dependencies:
npm install
  1. Look at app/config/config.js to change to your own apiKey for moviedb.
  2. Make sure to have redis installed. You can find a .zip here: https://redis.io/download . For Windows this is where I setup my version of redis https://github.com/dmajkic/redis/downloads .
  3. Make sure redis is on your PATH variable if you are using Windows. Type:
redis-server
  1. NOTE: You can use redis-cli to get a command line interface and test some of your queries and it helps to keep track of how many keys you have present.

  2. Make sure you run node in prodution mode: Run this command or something similar

NODE_ENV=production node index.js
  1. Open a new terminal and type:
webpack -p

for a smaller webpack build, or

webpack -w

if you want to edit the React Components

How it works

  1. The setup is mostly done in the main index.js file notably using compression to get a little extra information sent to the client.
  2. The routes.js just off of the app/ folder is doing the routing using a controller located in the app/controller folder where it is meant to be extended for other methods such as put/create/delete. I didn't use anything other than get because you are leveraging information mostly from other api's for this use case.
  3. The movieTrailerController has one main method where it is sending the api request based off of the url. If the url has data already in the redis cache, then it will return that to the user instead.
    If there is no matching url then nothing new will render on the front-end.
    If there is data, then it will use the imdb id as a foreign key to get the youtube key.
    NOTE: This is a nuance of the data, so if there is a movie that doesn't have an imdb key, then it won't find the trailerUrl and nothing will render from that.
    From there before returning the data, it will add the new key into the redis cache using hmset.
    In order to benefit from the cache, the trade-off here is that using hmset/hgetall you can use the JSON data, this will only work because the data is one level-deep. Otherwise you can use a hget/hset and appending all the values into strings.
    UPDATE: I changed the method to hget/hsetex with the expiry of one day so that the data will be up to date within one day from the imdb info stored in the viaplay api(if it changes).
  4. The components are located in the app/components portion where axios was used to send client requests. I stuck with a SPA because there wasn't a need for another endpoint to redirect users.
  5. The container folder is for "smart" components that have their own state, while the presentation folder is for the "dumb" components that are conditionally rendered when props are passed to them from the parent component. NOTE: I returned the first trailer since I figured the user didn't want a list of them. However this solution is easily extendable to include all the trailer videos by passing each of the video urls to respective Trailer Components.

Testing

  1. For the most part I had to do some research on Mocha so I left that for the last part even though it should have been done first.
  2. For the tests run: and the main file is within the /test folder.
mocha test

Next steps

  1. First there is always the use of nginx to serve static content. For this I have a very minimal amount of css so using nginx on that didn't seem necessary.
  2. Perhaps using multiple copies of the node server using different redis caches? Though I haven't research enough into redis to know for sure the full benefits of this versus other methods.
  3. Perhaps the use of Jest for front-end testing of React components (though the components were relatively simple and most of them were "dummy" components)
  4. Building up the API so that it does deal with POST,PUT, DELETE requests.

node-movie-api's People

Contributors

emilk15 avatar

Watchers

 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.