Profanity Check — Using IBM Cloud Functions — in a snap (less than 5 mins)

Vikash Gupta
1 min readJul 2, 2021

--

Create a IBM Cloud function action

  1. Create an IBM Cloud account or log in to an existing account.

2. Navigate to the Cloud Functions dashboard.

3. Select a namespace.

4. Click Start Creating > Quickstart Templates and select the Hello World template.

5. Create a package for your action by entering a unique name in the Package Name field.

6. Click Deploy. You created an action.

Prepare JavaScript app

Index.js

var Filter = require(‘bad-words’)function myAction(args){filter = new Filter();return {result:filter.isProfane(args.message)};}// export (expose) add to other modulesexports.myAction = myAction;global.main = myAction;

test.js for testing

var utils = require(‘./index.js’);console.log(utils.myAction({n:2}));

Package.json

{“name”: “my-action”,“main”: “dist/bundle.js”,“scripts”: {“build”: “webpack — config webpack.config.js”,“deploy”: “ibmcloud fn action update my-action dist/bundle.js — kind nodejs:12”},“dependencies”: {“left-pad”: “1.1.3”},“devDependencies”: {“webpack”: “³.8.1”}}

Webpack.config.js

var path = require(‘path’);module.exports = {entry: ‘./index.js’,output: {path: path.resolve(__dirname, ‘dist’),filename: ‘bundle.js’},target: ‘node’};

Install all dependencies locally.

npm install

Build the bundle

npm run build

Deploy

npm run deploy

Now the function is available over http for profanity check!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response