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

Create a IBM Cloud function action
- 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!