GithubHelp home page GithubHelp logo

occurrence-backend-node's Introduction

occurrence-backend-node

Backend code for the occurrence app in NodeJS.

(This is a part of assignment for TTT. Screenshots are included in the frontend repository, link to which is below.)

Heroku app: https://occ-node.herokuapp.com/ Frontend code: https://github.com/mohitk05/occurrence-frontend-react

This is an express app which gives 'N' frequently occuring words in the text file as requested from the frontend. Entry point for the app is server.js. This module initialises the express app and starts the server. When arequest hits the server, the process of calculating occurrences takes place. The code for this lies in a self built module called 'occurrence_module.js'. It is imported in myController.js and is passed the body of the text file. To fetch the text file data, a module called 'request' is used. After calculating the occurrences, the occurrence_module returns an array of arrays containing word-frequency pairs.

Modules used:

The routes handle the requests. The occurrence data fetching url is localhost:xxxx/find?num=3. Here 'num' is the request query item given by the frontend. This url runs the'myFunction' of 'myController'.

When a request hits the server ending in '/find', myFunction is run, which accesses the global object named 'global_occ' which is an array of arrays having pairs or word and occurrence frequency. It slices the array accoring to the requested number and sends the response. In case the requested number is larger than length of global_occ then consider the number as the length of global_occ i.e. return all the words.

All the core calculation is done in occurrence_module. It uses a Map object to calculate occurrence frequency and converts them into an array of arrays, finally sorting it according to the frequency. This is returned to the calling step.

For hosting purposes, React app has been converted to static files under frontend/build. It has been placed on the same server as the Express app. Middleware is used to direct '/' requests to the React app. Hence when the Heroku app link is opened, the React app opens up first.

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.