Skip to content

ibnjunaid/trendsFunction

Repository files navigation

TrendsFunction

Open Source? Yes!

TrendsFunction is a serverless function, running on ibmcloud .

  • Fetch trends every 16 minutes
  • Save trend to mongoDB for futher analysis
  • Magic

Trendsfunction is the fetcher part of alldaytrends, This repoistory implements the serverless functions which routinely fetches trends .

Tech

trendsFunction uses a number of open source projects to work properly:

Installation

trendsFunction requires Node.js v10+ to run.

Install the dependencies and devDependencies and start the server.

$ cd trendsFunction
$ npm install 

Build and Bundle the code using webpack

$ npm run build

IBM Web Action pass a param object to main function as parameter, here we pass Twitter bearer token, MongoDB URI and and start and end of trends to fetch.

Create a file params.json with following configuration

{
    "URI":"Mongo connection string here",
    "TWITTER_TOKEN":"Bearer token here",
    "START":0,
    "END":75
}

Docker

trendsFunction creates a custom docker image as the images provided by ibmfunctions doesnt have mongoose.

# Using ibmfunctions action-nodejs-v12 container as base
FROM  ibmfunctions/action-nodejs-v12:1.0.1
# Create a new container and add mongoose to it
RUN npm install mongoose
# Now
# Build and tag using `docker build -t <docker-username>/<container-name>:<version>`
# Push to public docker container registery `docker push <docker-username>/<container-name>:<version>`

Deployment

ibmcloud fn action create <action-name> --docker <docker-repo> -P <path-to-params.json> ./dist/bundle.js --main global.main --web true

License

GPL

Free Software, Hell Yeah!