From b9afb23d12dcae1e09f8d04c72143c5ddaa34aea Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Fri, 16 Jul 2021 16:27:00 -0400 Subject: delete conflicting/orphaned docs (zh-CN) (#1412) * delete conflicting docs (zh-CN) * and redirects * do orphaned as well * fix * remove more orphans * revert orphaned docs that can identify origin * move orphaned docs to current loc * adjust slug path * fix redirect change from rebase Co-authored-by: Irvin --- .../orphaned/learn/how_to_contribute/index.html | 86 -------- .../learn/html/forms/html5_updates/index.html | 145 ------------ .../learn/html/forms_and_buttons/index.html | 44 ---- .../installing_on_pws_cloud_foundry/index.html | 243 --------------------- 4 files changed, 518 deletions(-) delete mode 100644 files/zh-cn/orphaned/learn/how_to_contribute/index.html delete mode 100644 files/zh-cn/orphaned/learn/html/forms/html5_updates/index.html delete mode 100644 files/zh-cn/orphaned/learn/html/forms_and_buttons/index.html delete mode 100644 files/zh-cn/orphaned/learn/server-side/express_nodejs/installing_on_pws_cloud_foundry/index.html (limited to 'files/zh-cn/orphaned/learn') diff --git a/files/zh-cn/orphaned/learn/how_to_contribute/index.html b/files/zh-cn/orphaned/learn/how_to_contribute/index.html deleted file mode 100644 index 6b36cfc838..0000000000 --- a/files/zh-cn/orphaned/learn/how_to_contribute/index.html +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: 如何向MDN的学习区做贡献 -slug: orphaned/Learn/How_to_contribute -tags: - - MDN 元信息 - - 初学者 - - 学习 - - 引导 - - 指南 - - 文档 - - 贡献 -translation_of: Learn/How_to_contribute -original_slug: learn/How_to_contribute ---- -
{{LearnSidebar}}
- -

可能您是第一次看到这个页面,也可能您经过层层搜索而来。我们猜测您找到这里,是希望向 MDN 学习区做贡献——棒极了!

- -

这篇文档将告诉您如何提高 MDN 学习区资料的质量。您可以做的事情各种各样,取决于您有多少时间,以及您的身份:初学者Web 开发者,还是教师

- -
-

注意:这篇指南会告诉您如何撰写文章来帮助他人学习 Web

-
- -

寻找特定任务

- -

贡献者向学习区做出贡献的方法通常是阅读文章、修复排版错误并提出改进。我们同时欢迎您向我们的 GitHub 源 添加示例。若您还想了解需要做的其他事项,请与我们联系。

- -

在学习新知识的同时做出贡献是一件乐趣无穷的事。如果您感到迷茫或者有疑问,不用犹豫,通过邮件列表或 IRC 频道联系我们(本页底部有更详细的信息)。Chris Mills 是学习区的主题发布人——您也可以直接和他联系。

- -

以下章节为您的任务提供概要思路。

- -

我是初学者

- -

好极了!对于创建学习资源和提供反馈,初学者们至关重要。作为目标受众,您对这些文章具有独特的视角,这让您成为我们团队中的无价之宝。真的,如果您正在通过某篇文章学习知识却卡住了,或者您觉得这篇文章看起来有点令人费解,您既可以自行改正,也可以把问题告诉我们以便我们去改正它。

- -

下面是几种建议的贡献方式:

- -
-
为文章添加标签5 分钟
-
为文章添加标签是最简单的贡献方式。利用标签来呈现信息是我们的特色之一,因此添加标签对我们来说是非常有价值的贡献方式。您可以先从还没有标签的词汇条目学习文章开始。
-
阅读并复核词汇条目5 分钟
-
我们希望,作为初学者的您能用您的视角来审视我们所写的内容。如果您感到某个词汇条目难以理解,这说明该条目需要改进。您可以做任何觉得有必要的修改。如果您感到自己的技能不足以修改词汇条目,也可以通过邮件列表告诉我们。
-
撰写词汇条目20 分钟
-
这是学习新知识的最有效的方式了。挑选一个想要深入了解的概念,根据您所学的,撰写关于这个概念的词汇条目。“向他人解释”,这是巩固已学知识的最佳方式之一,既帮助您深入理解,同时也帮助了他人。这就是共赢!
-
阅读并复核学习文章2 小时
-
这与上述“复核词汇条目”非常类似,只是由于文章更长,因此要花更多时间。
-
- -

我是 Web 开发者

- -

太棒了!我们太需要您的专业技能了,这确保我们向初学者提供的内容技术准确。考虑到这部分内容用于供他人学习,我们希望您提供的解释尽可能表述简单,但又不至于无用。我们首先考虑易于理解,而非过度精确。

- -
-
阅读并复核词汇条目5 分钟
-
我们希望作为 Web 开发者的您,能让我们的文章内容技术准确而又不至于太学究气息。您可以做任何认为有必要的修改。如果您想在编辑前讨论内容,可以通过邮件列表IRC 频道联系我们。
-
撰写词汇条目20 分钟
-
阐述技术词汇是一种很好的学习方法,它能帮助您用准确而简单的方式把握技术细节。初学者非常需要准确清晰的术语定义。我们有许多缺乏定义的术语需要您来完善,请放手去做吧!
-
阅读并复核学习文章 (2 小时)
-
这与上述“复核词汇条目”一样,只是由于文章更长,因此要花更多时间。
-
撰写学习文章 (4 小时或者更多)
-
MDN 缺少朴素直白的文章以介绍如何使用 Web 技术(HTMLCSSJavaScript 等等)。我们还有很多陈旧的文档内容,需要复核或重构。发挥您的聪明才智,造福 Web 技术初学者吧!
-
创建练习、代码样例或交互式学习工具 (? 小时)
-
亲自实践的学习效果更佳,因此我们希望所有的学习文章都包含“主动学习 (active learning)”材料,比如练习、或者交互式内容。这些材料能够帮助用户熟练运用文章中详述的概念。制作“主动学习”材料的方式很多,比如使用 JSFiddle 或类似工具创建代码样例,或者使用 Thimble 构建可解析的交互式内容。总而言之,释放您的创造力吧!
-
- -

我是教师

- -

MDN 长期以来都拥有卓越的技术,但对于传授知识的最佳方法,我们仍然缺乏深刻的见解。我们需要教育工作者的参与,从而确保我们的材料为读者提供良好而实用的教育方法。

- -
-
阅读并复核词汇条目 (15 分钟)
-
检查词汇条目,并对任何您认为有必要的地方进行修改。如果您想在编辑前讨论内容,可以通过可以通过邮件列表IRC 频道联系我们。
-
撰写词汇条目 (1 小时)
-
为了满足初学者的需求,在词汇表中对术语进行清晰简明的定义、对概念进行基本总体的描述至关重要。您的教育经验对于创建优秀的词汇条目大有裨益;我们有许多缺乏定义的术语需要您来完善,请放手去做吧!
-
向文章中添加插图或图表 (1 小时)
-
您一定了解图表在学习材料中的价值。我们的文章内容总是缺乏图表,而您正好可以大展身手。您可以从缺少图表内容的文章中选择一些,为其创建插图。
-
阅读并复核学习文章 (2 小时)
-
这与上述“复核词汇条目”类似,只是由于文章更长,因此要花更多时间。
-
撰写学习文章 (4 小时)
-
我们需要朴素直白的文章,介绍 Web 生态体系以及其他相关的功能主题。这些文章的目标是教育性,而非领域百科。文章应当涉及什么、如何表述,您在这方面的丰富经验大有帮助。
-
创建练习、测验或者交互式学习工具 (? 小时)
-
我们希望所有的学习文章都包含“主动学习 (active learning)”材料,比如练习、或者交互式内容。这些材料能够帮助用户学习并拓展理解文章中详述的概念。您可以做很多事情——创建测验、用 Thimble 构建可解析的交互式内容——总之,释放您的创造力吧!
-
创建学习路线 (? 小时)
-
为了提供循序渐进、易于理解的教程,我们需要把学习材料组织成体系化的路线。这个过程将收集已有的材料,并找出缺失的内容,然后用新文章填补空缺。
-
diff --git a/files/zh-cn/orphaned/learn/html/forms/html5_updates/index.html b/files/zh-cn/orphaned/learn/html/forms/html5_updates/index.html deleted file mode 100644 index 5d96e5faff..0000000000 --- a/files/zh-cn/orphaned/learn/html/forms/html5_updates/index.html +++ /dev/null @@ -1,145 +0,0 @@ ---- -title: HTML 中的表单 -slug: orphaned/Learn/HTML/Forms/HTML5_updates -tags: - - HTML5 - - HTML5 form updates - - form -translation_of: Learn/HTML/Forms/HTML5_updates -original_slug: Web/Guide/HTML/Forms_in_HTML ---- -
HTML5中的表单元素和属性提供了比HTML4更多的语义标记,并取消了大量的在HTML4不可缺少的脚本和样式。HTML5中的表单功能为用户提供了更好的体验,使表单在不同网站之间更一致,并向用户提供有关数据输入的即时反馈。它们还为使用禁用脚本的浏览器的用户提供相同的用户体验。
- -
 
- -
本文总结了HTML5中的表单变化。有关使用表单的详细指南,请参阅我们更多的HTML表单指南
- -
 
- -

<input> 元素

- -

{{HTMLElement("input")}} 的 {{htmlattrxref("type", "input")}} 特性拥有更多的值。(请观看 {{HTMLElement("input")}} 获得完整列表)

- - - -

 {{HTMLElement("input")}} 元素也拥有一些新的特性。

- - - -

text input

- -
-
 
-
- -

这个程序段段定义了一个用户可以输入的一行input。

- -
<form>
-  Enter your Name <input type="text" name="name">
-</form>
- -

checkboxes

- -

这个程序段允许用户选择多个选项。

- -
<input type="checkbox" name="chk" value="" checked> Do you want the newsletter
- -

Radio < input> element

- -
<form>
-  <input type="radio" name="frequency" value="daily">Daily<br>
-  <input type="radio" name="frequency" value="weekly">Weekly<br>
-  <input type="radio" name="frequency" value="monthly">Monthly<br>
-  <input type="radio" name="frequency" value="yearly">Yearly
-</form>
- -

<form> 元素

- -

{{HTMLElement("form")}} 元素有了一个新特性:

- - - -

<datalist> 元素

- -

{{HTMLElement("datalist")}} 元素会在填写 {{HTMLElement("input")}} 字段时,显示一列 {{HTMLElement("option")}} 作为提示。

- -

你可以使用 {{HTMLElement("input")}} 元素上的 {{htmlattrxref("list", "input")}} 特性来将一个特定的 input 与特定的 {{HTMLElement("datalist")}} 元素做关联。

- -

<output> 元素

- -

{{HTMLElement("output")}} 元素表示计算的结果。

- -

你可以使用 {{htmlattrxref("for", "output")}} 特性来在 {{HTMLElement("output")}} 元素与文档内其他能够影响运算的元素(例如,input 或参数)建立关联。 {{htmlattrxref("for", "output")}} 特性的值是以空格做分隔的其他元素的 ID 列表。

- -

{{non-standard_inline}} Gecko 2.0 (其他浏览器并非如此) 支持为 {{HTMLElement("output")}} 元素自定义有效性约束(validity constraints)与错误信息,可以对其使用如下 CSS 伪类:{{Cssxref(":invalid")}}, {{Cssxref(":valid")}}, {{Cssxref(":-moz-ui-invalid")}},与 {{Cssxref(":-moz-ui-valid")}}。在如下情况会显得很有用:例如计算结果违反了业务规则,但却并非因为特定的 input 值出现错误(例如,「百分比总数不能超过100)。

- -

placeholder 特性

- -

{{htmlattrxref("placeholder", "input")}} 特性作用于 {{HTMLElement("input")}} 与 {{HTMLElement("textarea")}} 元素上,提示用户此域内能够输入什么内容。placeholder 中的文本不能包含回车与换行。

- -

autofocus 特性

- -

{{htmlattrxref("autofocus", "input")}} 特性让你能够指定一个表单控件,当页面载入后该表单自动获得焦点,除非用户覆盖它,例如在另一个控件中输入值。一个文档内只有一个表单能够拥有 autofocus 特性,它是一个 Boolean 值。这个特性适用于 {{HTMLElement("input")}}, {{HTMLElement("button")}}, {{HTMLElement("select")}},与 {{HTMLElement("textarea")}} 元素。例外情况是,如果一个 {{htmlattrxref("autofocus", "input")}} 元素的 {{htmlattrxref("type", "input")}} 特性值设置成了 hidden,则 autofocus 无法生效(就是说,你无法让一个隐藏控件自动获得焦点)。

- -

label.control DOM 属性

- -

HTMLLabelElement DOM 接口除了为 {{HTMLElement("label")}} 元素提供了对应的特性外,还提供了一个额外的属性。 control 属性返回被打上标签的控件,就是 label 适用的控件,由 {{htmlattrxref("for", "label")}} 特性(如果定义的话) 或是第一个后代元素控件来确定。

- -

约束验证

- -

HTML5 为客户端表单的验证提供了语法与 API。当然这些功能无法取代服务器端验证,出于安全性与数据完整性的考虑,服务器端验证仍然必不可少,但是客户端验证能够通过对输入数据的即时反馈来提供良好的用户体验。

- -

如果 {{HTMLElement("input")}} 元素设置了 title 特性,当验证失败时,特性值会显示在提示信息中。如果 title 设置为空字符串,则不会显示提示信息。如果没有设置 title 特性,会使用标准验证信息(例如通过 {{htmlattrxref("x-moz-errormessage")}} 特性指定,或调用 setCustomValidity() 方法) 代为显示。

- -
注意: 约束验证不支持表单中的 {{HTMLElement("button")}} 元素;若想基于表单的验证结果来改变按钮的样式,可以使用 {{cssxref(":-moz-submit-invalid")}} 伪类。
- -

约束验证的 HTML 语法

- -

下列 HTML5 语法中的条目用于为表单数据指定约束。

- - - -

此外,若要阻止对表单进行约束验证,你可以在 {{HTMLElement("form")}} 上设置 {{htmlattrxref("novalidate", "form")}} 特性,或在 {{HTMLElement("button")}} 与 {{HTMLElement("input")}} 元素(当 {{htmlattrxref("type", "input")}} 是 submit 或 image)上设置 {{htmlattrxref("formnovalidate", "button")}} 特性。这些特性指定了当表单提交时不做验证。

- -

约束验证 API

- -

下面这些 DOM 属性与方法和约束验证相关,能够在客户端脚本中使用:

- - - -
{{HTML5ArticleTOC}}
diff --git a/files/zh-cn/orphaned/learn/html/forms_and_buttons/index.html b/files/zh-cn/orphaned/learn/html/forms_and_buttons/index.html deleted file mode 100644 index 443876e6a3..0000000000 --- a/files/zh-cn/orphaned/learn/html/forms_and_buttons/index.html +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: 表单和按钮 -slug: orphaned/Learn/HTML/Forms_and_buttons -tags: - - 初学者 - - 指引 - - 文章 - - 表单 -translation_of: Learn/HTML/Forms_and_buttons -original_slug: learn/HTML/Forms_and_buttons ---- -

{{draft}}{{LearnSidebar}}

- -

表单和按钮是Web的一个非常重要的部分 - 这些允许您的站点访问者输入数据并将其发送给您(例如注册,登录和反馈表单),并且您可以实现控制以控制复杂功能(例如提交表单) 到服务器,或暂停播放视频。)这个模块可以帮助您入门。

- -

先决条件

- -

在开始本单元之前,您应该对HTML的基础知识有一定的了解,如HTML简介中所述。 如果你没有通过这个模块(或类似的东西),先完成它,然后再回来!

- -
-

Note: 如果你是在计算机/平板电脑等其他你无法创建文件的设备上的话,你可以尝试在在线代码编辑平台上运行代码例如 JSBin 或 Thimble.

-
- -

向导

- -

本模块包含以下的文章

- -
-
表单和按钮基础知识(Form and button basics)
-
     在本文中,我们将向您介绍HTML表单的基础知识,包括它们的用途,基本功能和常用表单控件。 我们还将了解HTML按钮以及如何使用它们。
-
形成语义和结构
-
     存在许多元素,允许我们将表单结构化为更易于使用和访问 - 其中一些是专门的表单元素,其中一些是通用HTML容器。 在本文中,我们将介绍创建表单结构的最佳实践。
-
高级表单功能
-
       在这里,我们将介绍HTML表单中可用的一些更高级的功能,例如数据列表,进度条,滑块以及最小值和最大值。
-
表格验证
-
     在我们的最终表单文章中,我们将讨论表单验证,讨论为什么有必要,并查看HTML选项卡提供的一些功能,以便客户端验证表单数据。
-
- -

练习

- -
-
表单练习
-
等待完成(to be done)
-
diff --git a/files/zh-cn/orphaned/learn/server-side/express_nodejs/installing_on_pws_cloud_foundry/index.html b/files/zh-cn/orphaned/learn/server-side/express_nodejs/installing_on_pws_cloud_foundry/index.html deleted file mode 100644 index 125d31931d..0000000000 --- a/files/zh-cn/orphaned/learn/server-side/express_nodejs/installing_on_pws_cloud_foundry/index.html +++ /dev/null @@ -1,243 +0,0 @@ ---- -title: 在 PWS/Cloud Foundry 上,安装 LocalLibrary -slug: orphaned/learn/Server-side/Express_Nodejs/Installing_on_PWS_Cloud_Foundry -translation_of: Learn/Server-side/Express_Nodejs/Installing_on_PWS_Cloud_Foundry -original_slug: learn/Server-side/Express_Nodejs/Installing_on_PWS_Cloud_Foundry ---- -
{{LearnSidebar}}
- -

本文提供了如何在 Pivotal Web Services PaaS cloud 云上安装 LocalLibrary的实际演示 - 这是 Heroku 的全功能,开源替代品,Heroku 是我们教程第 7 部分中使用的 PaaS 云服务。如果您正在寻找 Heroku(或其他 PaaS 云服务)的替代方案,或者只是想尝试不同的东西,PWS / Cloud Foundry 绝对值得一试。

- -

为什么是 PWS?

- -

Pivotal Web Services 是开源云代工平台的公共实例。它是一个多语言平台,支持许多不同的语言,包括Node.js,Java,PHP,Python,Staticfiles 和 Ruby。它有一个免费试用版,对于运行 Node 应用程序非常有效!由于 Node 和 Express 是开源项目,因此与使用 Cloud Foundry 等开放式部署平台保持一致。您可以深入了解应用程序的托管方式。

- -

使用PWS有多种原因!

- - - -

PWS 是如何工作的?

- -

PWS通过容器来运行网站和应用已经有些年头了。Cloud Foundry一开始采用的容器技术名为Warden,现在使用的是名为Garden的容器系统。这些技术与流行的Docker容器很相似,而且事实上Cloud Foundry云平台的很多设施都支持部署Docker容器。

- -

使用Cloud Foundry云平台的好处之一是您不需要创建容器规范,因为Cloud Foundry的构建包会基于最新的组件来生成它们。由于容器是临时部署的,而且可能随时被清理并部署到云中的其他位置,所以Cloud Foundry云平台上的应用需要遵循十二要素准则。如此可以确保您的应用和平台使用最新的软件。一个应用程序可以包含多个实例,在这些实例中,应用程序被放置到冗余容器中,从而实现应用程序的高可用性。Cloud Foundry会自动处理相同实例之间的所有负载平衡。这允许您扩展应用程序的性能和可用性。

- -

由于文件系统是临时的,所以任何临时存储或服务都应该使用备份服务放置到其他地方。这可以通过使用不同提供商提供的市场服务或通过用户自己提供的服务来实现。

- -

What do we cover below?

- -

This post covers how to modify the LocalLibrary application from the tutorial for deployment on PWS and Cloud Foundry. In doing so, it covers the basics of deploying any node.js application to PWS with the following steps.

- - - -

So let's get started. You have two options, you can go through the tutorial from the beginning or you can just download the completed project and modify it from there for use on PWS. To do the latter, you can do the following from a terminal:

- -
git clone https://github.com/mdn/express-locallibrary-tutorial
- -

You'll then need to follow the preparation steps listed in the Getting your website ready to publish section of Express Tutorial Part 7: Deploying to production, before then following the steps listed below.

- -
-

Note: This work flow is based on the Mozilla Heroku work flow in the main Express/Node tutorial series for consistency, to help readers compare and contrast. 

-
- -

Modifying the LocalLibrary for PWS

- -

Deployment of a Node application on Cloud Foundry takes the following steps. Using the downloaded 'cf' CLI tool on your environment, your source code and supporting metadata files are uploaded to Cloud Foundry which will assemble and package the components of your application. Note that your files need to be located on your system to deploy or as a zip archive somewhere accessible on the internet. We'll assume the former.

- -

This means, no assumptions about which source control system is used. As long as you have a complete source tree in your local file system you can deploy the app. There are some things you have to make available to ensure the correctly assembly of your Node application. First Cloud Foundry cf CLI will look for the presence of the 'package.json' file to determine the dependencies and download the necessary components. The rules of this assembly are defined in Cloud Foundry's nodejs buildpack. An optional cloud foundry manifest file can specify information about your application such as name, size and start command if non-standard. In addition to deploying the application, the cf CLI tool can also configure services, set environment variables and view logs. That's all the overview you need in order to get started (see Getting Started on Pivotal Web Services for a more comprehensive guide). Let's start making the changes so you'll need to deploy the LocalLibrary application to  PWS.

- -

Set node version

- -

The package.json contains everything needed to work out your application dependencies and what file should be launched to start your site. Cloud Foundry and PWS detects the presence of this file, and will use it to provision your app environment. The only useful information missing in our current package.json is the version of node. We can find the version of node we're using for development by entering the command:

- -
node --version
-# will return version e.g. v6.10.3
- -

Open package.json with a text editor, and add this information as an engines > node section as shown (using the version number retrieved above).

- -
{
-  "name": "express-locallibrary-tutorial",
-  "version": "0.0.0",
-  "engines": {
-    "node": "6.10.3"
-  },
-  "private": true,
-  ...
-
- -

Database configuration

- -

So far in this tutorial we've used a single database that is hard coded into the app.js file. Normally we'd like to be able to have a different database for production and development, so next we'll modify the LocalLibrary website to get the database URI from the OS environment, and otherwise use our development database that we added manually earlier. Cloud Foundry has a very flexible services model that enables multiple services of the same type to exist in the environment. It stores all services related configurations in a single parseable JSON object called VCAP_SERVICES. A typical VCAP_SERVICES variable looks like this:

- -
{
- "VCAP_SERVICES": {
-  "mlab": [
-   {
-    "credentials": {
-     "uri": "mongodb://CloudFoundry_test_dev:somecr8zypassw0rd@dbhost.mlab.com:57971/CloudFoundry_dbname"
-    },
-    "label": "mlab",
-    "name": "node-express-tutorial-mongodb",
-    "plan": "sandbox",
-    "provider": null,
-    "syslog_drain_url": null,
-    "tags": [
-     "Cloud Databases",
-     "Developer Tools",
-     "Web-based",
-     "Data Store",
-    ],
-    "volume_mounts": []
-   }
-  ]
- }
-}
-
-
- -

Writing the code to extract and parse this environment variable is not hard, but it doesn't add a lot of value when others have written libraries to do this. In this case, there is a node.js package we can use called cfenv.

- -

This will download the cfenv module and its dependencies, and modify the package.json file as required. Open app.js and find the block with all the 'requires' that load the modules into your application. In this example look for the line that looks something like this:

- -
var expressValidator = require('express-validator');
- -

If you cannot find that exact line, look for the blocks of 'requires' and look for the last one. Add the following text after it:

- -
var cfenv = require('cfenv');
- -
    -
  1. -

    To install the package, go to your terminal and make sure you are in the directory where the package.json file for LocalLibrary is. From the command line, type:

    - -
    npm install cfenv
    -
  2. -
  3. -

    Now that you have loaded the module, this next line will instantiate an object that will contain the app and services information required for deployment. Add the following after the line that contains app.use(helmet());

    - -
    // Set up CF environment variables
    -var appEnv = cfenv.getAppEnv();
    -
    - -

    When this line executes, all the Cloud Foundry application environment information will become available to the application in the appEnv object.

    -
  4. -
  5. -

    Now it is time to update the application to use the database configured by the platform. Find the line that sets the mongoDB connection variable. It will look something like this:

    - -
    var mongoDB = process.env.MONGODB_URI || dev_db_url;
    -
  6. -
  7. -

    You will now modify the line with the following code  appEnv.getServiceURL('node-express-tutorial-mongodb') to get the connection string from an environment variable that is being managed by the cfenv  module. If no service has been created and bound it will use your own database URL you created as part of the tutorial instead of the one from the environment. So replace the line above with the following:

    - -
    var mongoDB = appEnv.getServiceURL('node-express-tutorial-mongodb') || dev_db_url;
    -
    -
  8. -
  9. -

    Now run the site locally (see Testing the routes for the relevant commands) and check that the site still behaves as you expect. At this point your app is ready to use with Cloud Foundry and Pivotal Web Services.

    -
  10. -
- -

Get a Pivotal Web Services account

- -

To start using Pivotal Web Services you will first need to create an account (skip ahead to Create and upload the website if you've already got an account and have already installed the PWS cf CLI client).

- - - -

Install the cf CLI client

- -

The cf CLI client is a software tool for managing and deploying your application. Download and install the PWS cf CLI client by following the instructions on Pivotal Web Services or downloading directly from GIthub. Be sure to download the correct version for your computer. After the client is installed you will be able run commands, for example to get help on the client:

- -
cf help
-
- -

We'll now go through the steps to login to PWS using the CLI and deploy — or in Cloud Foundry parlance "push" your app.

- -

Create and upload the website

- -

To create the app we navigate to the directory where our modified files are. This is the same directory where the LocalLibrary package.json file is located. First, let's tell the cf CLI which Cloud Foundry instance you want to use. We need to do this, since the cf CLI tool can be used with any standard Cloud Foundry system, so this command indicates which specific Cloud Foundry you are using. Enter the following terminal command now:

- -
cf api api.run.pivotal.io
- -

Next login using the following command (enter your email and password when prompted):

- -
cf login
-Email: enter your email
-Password: enter your password
- -

We can now push our app to PWS. In the below example. replace 'some-unique-name' with something you can remember that is likely to be unique. If it isn't unique, the system will let you know. The reason this name has to be unique to the PWS system is it is the address we will use to to access your LocalLibrary application. I used mozilla-express-tutorial-xyzzy. You should use something else.

- -
cf push some-unique-name -m 256MB
- -

Note the -m flag we added is not required. We just included it so that we only use 256MB of memory to run the app. Node apps typically can run in 128 MB, but we are being safe. If we didn't specify the memory, the CLI would use the default 1 GB of memory, but we want to make sure your trial lasts longer. You should now see a bunch of text on the screen. It will indicate that the CLI is uploading all your files, that it's using the node buildpack, and it will start the app. If we're lucky, the app is now "running" on the site at the URL https://some-unique-name.cfapps.io. Open your browser and run the new website by going to that URL.

- -
Note: The site will be running using our hardcoded development database at this time. Create some books and other objects, and check out whether the site is behaving as you expect. In the next section we'll set it to use our new database.
- -

Setting configuration variables

- -

You will recall from a preceding section that we need to set NODE_ENV to 'production' in order to improve our performance and generate less-verbose error messages.

- -
    -
  1. -

    Do this by entering the following command:

    - -
    cf set-env some-unique-name NODE_ENV production
    -
    -
  2. -
  3. -

    We should also use a separate database for production. Cloud Foundry can take advantage of a marketplace to create a new service and automatically bind it to your app. Bind means place the service database credentials in the environment variable space of the container running your application for you to access. Enter the following commands:

    - -
    cf create-service mlab sandbox node-express-tutorial-mongodb
    -cf bind-service some-unique-name node-express-tutorial-mongodb
    -
    -
  4. -
  5. -

    You can inspect your configuration variables at any time using the cf env some-unique-name command — try this now:

    - -
    cf env some-unique-name
    -
    -
  6. -
  7. -

    In order for your applications to use the new credentials you will have to restage your application, meaning that it will restart and apply the new environment variables. This can be done using the following — enter this command now:

    - -
    cf restage some-unique-name
    -
    -
  8. -
  9. -

    If you check the home page now it should show zero values for your object counts, as the changes above mean that we're now using a new (empty) database.

    -
  10. -
- -

Debugging

- -

The PWS cf client provides a few tools for debugging:

- -
>cf logs some-unique-name --recent  # Show current logs
->cf logs some-unique-name # Show current logs and keep updating with any new results
- -

Summary

- -

If you followed the above steps, you should have now deployed the LocalLibrary app to PWS. Well done! If the deployment wasn't successful, double check all the steps.

-- cgit v1.2.3-54-g00ecf