This a demo application with Node JS as Backend and Angular as frontEnd that calculates the N most frequently used words in a text file(remote file)
Install the dependencies and build the Angular dist folder For working with Client/Angular app $ npm install $ ng build --prod
Initialise a Firebase application in the root folder
$firebase init
Select the option for hosting and later select the required options for rewriting the app to SPA.
This also lets the user detail the application to select the folder to which the command firebase serve to look at.
Select the app name to which we need to deploy the application to.
$firebase deploy
Above command deploys the local application build to firebase.
code is available at /server folder
Run npm start for running node server. Navigate to http://localhost:3000/.
It is currently hosted on Heroku. https://pure-sierra-13501.herokuapp.com
code is available at /client/tttClientTest folder
Run ng serve for running the angular server locally. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
It is currently hosted on firebase. https://tttclient-97cf4.firebaseapp.com/
This hosting is done using the Github pipelining feature of Heroku, for every push to the piepelined branch, the Node app gets built and deployed.(Heroku hosting is selected as Firebase charges and doesnot let free trail users use the 3rd party API calls.)
-
Server
- An API,
/apiis created with help of express library. This api is responsible to get the frequency details(N) and do all the necessary operations to find the top N most words present in the string generated by accessinggiven URL - The function splitByWords() splits the string(obtained after making remote call to
given URL) and returns an array of words . - The function createWordMap(N, wordsArray) takes in the frequency number and the array of words, gets the count of each word.
- After grouping the words with same frequency we use the function getUnique(arr, comp) to remove duplicate entries if any.
- Later splice the array to send only the top N most words in the text file/string.
- An API,
-
Client
- The main app Component loads the selector
app.component.tsis responsible for all the logical code.- This file has a function apiCall() which inturn has the logic to subscribe HttpClient to access the API
/apiand send the frequency details (N) to server. - the HTTPClient is injected upon importing from angular/common/http
app-routing.module.tscontains the route details of each component, it provides a uri to access the component/page.
-
Angular 7
- HttpClient
- Bootstrap
-
Node JS
- Express
- body-parser
- cors
- request
- firebase-tools
.png)
.png)
.png)
.png)
.png)
.png)
.png)