node 大写_大写Node.js模块

node 大写

Today, let’s see a third party module that helps us in working with upper-case letters without necessarily typing them in upper-case in our source code.

今天,让我们看一个第三方模块,它可以帮助我们处理大写字母,而不必在源代码中以大写字母键入它们。

You may find it useless! But it’s very important.

您可能会发现它没有用! 但这很重要。

For example, you may have a form where you require your users to fill in upper-case letters only. You may wish to add a function where any typed in the letter appears in upper-case even though typed in lower-case from the keyboard.

例如,您可能有一个表单,要求您的用户仅填写大写字母。 您可能希望添加一个功能,即使从键盘输入小写字母,字母中的任何字母都以大写形式显示。

Like said before, Node modules are like libraries which help us perform specific tasks. Node.JS is always considered powerful because it has a very large ecosystem of third-party modules.

如前所述,Node模块就像是可以帮助我们执行特定任务的库。 Node.JS一直被认为是功能强大的,因为它具有非常庞大的第三方模块生态系统。

The upper-case module is a third-party module built by some experts to help us.

大写模块是一些专家构建的第三方模块,可以帮助我们。

Take Note! You should have Node.js installed in your PC.

做记录! 您应该在PC中安装了Node.js。

With Node.js already up and running, let’s get started.

在Node.js已经启动并运行的情况下,让我们开始吧。

Now, let’s get started.

现在,让我们开始吧。

First of all, install the upper-case module by typing npm install upper-case via the command line.

首先,通过在命令行中键入npm install upper-case来安装大写 模块

《node 大写_大写Node.js模块》

Wait for a while as it downloads.
NB: Internet required!

等待下载。
注意:需要互联网!

Take note that only third party modules are installed via command line unlike built in modules which comes along with the node.js environment when downloaded…

请注意,不同于第三方模块在下载时随Node.js环境一起提供的内置模块,仅通过命令行安装了第三方模块。

Let’s look at a basic use of the upper-case module.

让我们看一下大写模块的基本用法。

We’ll create an http server that will output hello world in capital letters but written in small letters in the source code.

我们将创建一个http服务器,该服务器将以大写字母输出问候世界,但在源代码中以小写字母书写。

Open a text editor and type the following code and save it with the file name app.js:

打开一个文本编辑器,输入以下代码,并将其保存为文件名app.js

var http = require('http');  // includes the http module
var uc = require('upper-case'); // include the upper-case module
http.createServer(function (req, res) {
   
    res.writeHead(200, {
   'Content-Type': 'text/html'});
    res.write(uc("hello world!")); // assign the upper-case module
    res.end();
}).listen(8080); // port number

Note: The file should be saved in your default Node.js directory.

注意:该文件应保存在默认的Node.js目录中。

Initiate the JavaScript file at the console by typing node app.js

通过键入节点app.js在控制台上启动JavaScript文件

Take Note! : Your command line directory should be same with Node.js module directory.

做记录! :您的命令行目录应与Node.js模块目录相同。

Finally, open your browser and navigate to http://localhost:8080

最后,打开浏览器并导航到http:// localhost:8080

《node 大写_大写Node.js模块》

Thanks for coding with me. Your comments are most welcome.

感谢您与我一起编码。 非常欢迎您发表评论。

翻译自: https://www.includehelp.com/node-js/upper-case-node-js-module.aspx

node 大写

    原文作者:cumtb2002
    原文地址: https://blog.csdn.net/cumtb2002/article/details/107792782
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞