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 .
trendsFunction uses a number of open source projects to work properly:
- node.js - evented I/O for the backend
- Express - fast node.js network app framework @tjholowaychuk
- Webpack - the build system
- typescript - the typed javascript
- ibmcloud - Awesome place to deploy apps
- docker - get your code a home
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
}
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>`
ibmcloud fn action create <action-name> --docker <docker-repo> -P <path-to-params.json> ./dist/bundle.js --main global.main --web true
GPL
Free Software, Hell Yeah!