未加星标

Creating a Nodejs App with Watson AlchemyAPI and CloudantDB

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

WIP

Requirements:

a Bluemix.net account a Github account Git on localhost, install Git your favorite code editor, e.g. Sublime 3 ,

Overview:

Setup Setup Details Add Watson AlchemyAPI Add Cloudant DB Setup Login to Bluemix, in a separate tab login to Github, Create a ‘Node.js Cloudant DB Web Starter’ Boilerplate, named ‘<username>-nodejs-app1’, click CREATE Go to ‘Overview’, scroll down to ‘Continuous delivery’ and click ‘Enable’ In the ‘Toolchain Settings’, change the name of the Toolchain to ‘<username>-nodejs-app1’, and click Create, If the Github THINK or CODE icon displays a configuration error, from the block’s dropdown icon in the topright, click the ‘Configure’ link to correct the configuration of your Github account, Go to your Github account and make sure that the repository for the new Bluemix app is created successfully, Copy the Git URL, on localhost open a commandline terminal, change to your development directory and clone the new repository,
cd ~/dev/src/bluemix git clone https://github.com/remkohdev/remkohdev-nodejs-app1.git cd remkohdev-nodejs-app1 Open the project directory in your favorite editor, Open the ‘package.json’ file and change the ‘name’ property to ‘<username>-nodejs-app1’, From the commandline, in your project directory,
git status git add . commit -m "change package.json name property" Before pushing the staged changes to the remote master directory, first go back to the Toolchain of your application, and click the ‘DELIVER’ window or ‘Delivery pipeline’, Now from the commandline push changes to the remote repository, this should trigger the ‘Build Stage’ automically, as it is by default configured to trigger after code changes are detected in the source code repository, i.e. on Github, You should see that your Github repository is updated, and almost instantly see the Build Stage being triggered, upon successful build, the Deploy Stage’ is triggered, To debug, you have several options: In the Build or Deploy stage, click the ‘View logs and history’, In the Application details page, go to ‘Logs’, Go to ‘Getting Started’, and follow the instructions to install the CloudFoundry commandline ‘cf’, and from the commandline, go to your project directory:
cd ~/dev/src/bluemix/remkohdev-nodejs-app1 cf login cf logs remkohdev-nodejs-app1 --recent Go to the Toolchains Overview page, open the ‘Eclipse Orion Web IDE’, and click the ‘Open the Logs’ icon from the top menu, You now have a very simple but quick cloud application running. Open the URL of your application http://<username>-nodejs-app1.mybluemix.net .
Creating a Nodejs App with Watson AlchemyAPI and CloudantDB
Setup Details

The following overview is anatomically not 100% correct, but it’s a good first cut.

Bluemix Architecture

Bluemix is the product name for the IaaS, PaaS and SaaS layers of IBM cloud. The IaaS of Bluemix is built on SoftLayer physical infrastructure and OpenStack. The PaaS of Bluemix is built with CloudFoundry, which supports Docker containers. The SaaS of Bluemix offers among other the IBM Watson APIs and direct integration with IBM Watson IoT platform.


Creating a Nodejs App with Watson AlchemyAPI and CloudantDB
Creating a Nodejs App with Watson AlchemyAPI and CloudantDB
CloundFoundry CommandLine Interface (CLI)

Documentation of the CF CLI can be viewed here .

Above I already used the CF cli to view a more detailed logs history of your application. There is also a Bluemix cli, which is an extension of the CF cli. Almost everything you do in Bluemix via the web UI, you can also do using the Bluemix or CF cli tool.

Just a small selection of CF cli commands:

cf api Change the endpoint to change regions. cf apps List all apps in your current space. cf bind-service Bind a service to your application. cf create-service Create a service instance. cf login Login to your Bluemix environment. cf marketplace List all services from the Bluemix marketplace.

For a complete overview, see the CF cli documentation .

In addition, to the default Bluemix or CF cli commands, you can add cli plugins to your cli environment, for instance the ‘ IBM-Containers ‘ plugin to use native Docker cli commands.

Toolchain

Step through the Toolchain.

Eclipse Orion Web IDE

Step through the Web IDE.

Add Watson AlchemyAPI

Let’s change the default application by adding a news search form to the home page, a Watson AlchemyAPI NewsData API and a news results page.

Go to the application detail page, click on the ‘Connections’ link, By default, 2 connections or services were added already, a monitoring connection and the Cloudant DB connection. Click the ‘Connect New’ button to add a new service, Filter by ‘Watson’, select the AlchemyAPI, click Create, and Restage the application, You can view the connection credentials in the Connections page and by clicking the ‘View Credentials’ button on the service icon, or go to Runtime, go to ‘Environment Variables’ and browse the ‘VCAP_SERVICES’ environment variable. This ‘VCAP_SERVICES’ variable is available to your application by loading the system environment variables. In Node.js,
if (process.env.VCAP_SERVICES) { var vcapServices = JSON.parse(process.env.VCAP_SERVICES); Create a News Search and Route Go to the ‘Eclipse Orion Web IDE’ and open the file ‘~/views/index.html’, Replace the current code in the ‘~/views/index.html’ with the following code, Press the ‘Deploy the App from the Workspace’ button, when the app is ready deploying, check the new home page, Open the file ‘~/app.js’ and add the following route, Implement the News Search

There are several ways to add an http request:

Nodejs includes an http server and client, JQuery AJAX.get() shorthand, NPM package XMLHttpRequest , NPM package Request ,

Add one of the following examples to the file ‘~/app.js’.

Nodejs https.request Example

The https class and the https.request method is the SSL variation of the HTTP class and the http.request method.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: GitDockerNode.jsPaaSOpenStackXMLIBMSaaS
分页:12
转载请注明
本文标题:Creating a Nodejs App with Watson AlchemyAPI and CloudantDB
本站链接:http://www.codesec.net/view/521474.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(30)