This simple Client-Server application finds the top N most frequently occuring words in a text file stored at a remote URL using web scraping. Live version of this application can be found here.
- How it works?
- Getting started
- Different Components of the code
- Libraries and Plugins used
- Test Cases
Stack used here is:
- Environment and all the dependencies for Backend is an RESTful web service using Node.js and Express.js Framework.
- Angular4 PRIMENG framework is used as the web interface(Frontend).
Clone this repository into your system.
- Navigate to ttt-assignment-freq-app/frontend in your terminal
- Run
npm installto install required dependencies - Run
ng build -prodto build the angular product and integrate and assemble all the components into a singleindex.htmlin "../public" folder
- Navigate to ttt-assignment-freq-app in your terminal
- Run
npm installto install required dependencies
- Navigate to ttt-assignment-freq-app in your terminal
- Run
node index - Go to your browser and open the link http://localhost:8080
- Try with different values of 'N'
It contains all the metadata information of the application like the packages and there versions. There are 2 package.json files - one in main app ttt-assignment-freq-app and another in ttt-assignment-freq-app\frontend folder.
- Creates an Express server named as
app - Add middlewares
corsandbody-parser - Add static file
\publicto the server - Creates API that renders
\public\index.htmlat the homepage http://localhost/ - Creates GET API that receives 'N' as parameter and then calls appropriate backend controller function
- Finally initiates the server at port no. 3000 of your local machine.
This is generated only after building the frontend folder using
ng build -prodStores the index.html file and its dependencies which is finally rendered at homepage.
Contains a function modules that computes a hash for a given string passed as an arguement to it.
Contains module
getTopNMostFrequentWordswhich takesreq,resandnextas parameters and sends JSON array of objects storing top N most frequently occuring words in http://www.terriblytinytales.com/test.txt as response inres.
This module web scrapes the whole web page at http://www.terriblytinytales.com/test.txt and then uses the text in HTML body which is then splitted into array of words.
Each word is then hashed and stored in the JSON object frequency with word and frequency properties storing the particular word and its frequency in the text file. This frequency array is then sorted according to property frequency.
And then top N elements of array frequency is stored in n_most_frequent_words and sent as response.
Stores all the source files of our angular project.
Stores all the .ts, .html, and .css files of the component rendered in main app component module.
Defines and exports a class storing data members of JSON object frequency
Defines the service, used by the component word-frequency, of making an HTTP GET request to the backend server.
- express
- cors
- body-parser
- request-promise
- cheerio
- path
- @angular
- primeng
- HttpClientModule from @angular/common/http
- FormsModule from @angular/forms
- InputTextModule, ButtonModule, DataViewModule, KeyFilterModule, TooltipModule from primeng