This app is built using the express application generator. It creates a simple form where the user can enter some text. After submitting the text, the app displays it back to the user. The app is designed to be extended by adding the Watson Language Translation API service to perform actions like identifying the language of the input text, or to translate it to a different language. All views are rendered using the EJS template language.
You can deploy this application to your IBM Cloud Foundry environment by clicking on this button. It will create a IBM Cloud Continous Delivery toolchain, copy this repository into a new repository and deploy it.
Once you have tried the application, use the IBM Cloud dashboard or Cloud Foundry cli to add the Watson Language Translation service to the app. Restage the app when prompted. The app will use this service to display the language of the message entered into the app.
- Install Node.js
- Clone this repository to a directory
git clone https://github.com/ibmecod/watson-parrot-nodejs.git
- cd into the app directory
- Run
npm install
to install the app's dependencies - Run
npm start
to start the app - Access the running app in a browser at the port shown on startup
When running locally, the code will not detect the language used in the input text. To enable language detection, create a Watson Language Translator service on IBM Cloud and bind it to an application copy in Cloud Foundry. Export the VCAP_SERVICES envrionment variable and define it to your environment before invoking npm start
- Install Docker CE
- Build a container image with the application using the Dockerfile
docker image build -t smart-parrot .
- Create a container from the image and run in a terminal
docker container run -it -p 6001:6001 smart-parrot
- Access the application locally at
http://localhost:6001/
When running locally as a container the application will not use the Watson Language Translator service and will just repeat what is typed into the form. But you can make it smarter by deploying on IBM Cloud Container Service with Kubernetes.
- Follow the Kubernetes Cluster Tutorial to create your own cluster on IBM Cloud.
- Install the IBM Cloud container registry cli and log in to the container registry service.
bx plugin install container-registry -r Bluemix
bx cr login
- Tag the docker image that was built locally using your IBM Cloud container registry namespace.
you can list your namespaces with
bx cr namespaces
docker image tag smart-parrot registry.ng.bluemix.net/<your-namespace>/smart-parrot
- Push the image to the IBM Cloud container registry.
docker image push registry.ng.bluemix.net/<your-namespace>/smart-parrot
- Add a copy of the Watson Language Translator service to your organization and space using the IBM Cloud catalog or the command-line using the instance name shown (to minimize edits in the deployment file).
bx service create language_translator lite mylanguagetranslator
- Bind the service to the cluster which will inject the service credentials as a Kubernetes secret.
you can list your cluster name(s) with
bx cs clusters
bx cs cluster-service-bind <your-cluster-name> default mylanguagetranslator
- Edit the
smart-parrot-deployment.yaml
file and update the<your-namespace>
field in the image url to your namespace. Deploy the application using the deployment file.
kubectl create -f smart-parrot-deployment.yaml
- Get your worker IP address(es) for the cluster.
bx cs workers <your-cluster-name>
- Access the application at
http://<worker-ip>:30801/
. With the Language Translator service bound to the cluster and associated with the pod for the deployment, the app is able to determine the language used in the message.