本文共 8409 字,大约阅读时间需要 28 分钟。
As we discussed in my initial Node JS Platform posts, Node JS has many modules to develop different kinds of functionality. Each Node JS Module is aimed to provide one or more kinds of services. Like other modules or packages, Express JS is also a module in Node JS Platform.
正如我们在最初的Node JS Platform帖子中所讨论的那样,Node JS具有许多模块来开发各种功能。 每个Node JS模块旨在提供一种或多种服务。 与其他模块或软件包一样,Express JS也是Node JS Platform中的模块。
In this post, we will discuss some basics of “Node: Express JS Module”. As it is very big and important module in Node JS Platform, we will discuss some advanced concepts of Express JS module in coming posts.
在本文中,我们将讨论“节点:Express JS模块”的一些基础知识。 由于它是Node JS平台中非常重要的模块,因此我们将在以后的文章中讨论Express JS模块的一些高级概念。
Express JS is a Light-weight Web Framework to develop Web Applications very easily and quickly in Node JS Platform. Latest Express JS Framework version is : 4.x.
Express JS是一个轻量级的Web框架,用于在Node JS平台中非常轻松快速地开发Web应用程序。 Express JS Framework的最新版本是:4.x。
Express JS Official Website: https://expressjs.com/
Express JS官方网站:https://expressjs.com/
In my previous post , we have developed an HTTP Server using Node JS “http” module. We can develop similar kind of HTTP Server or WebServer using Express JS Module too.
We will discuss on “How to develop a WebServer using Express JS Module” in coming posts.在我之前的文章 ,我们使用Node JS“ http”模块开发了一个HTTP Server。 我们也可以使用Express JS Module开发类似类型的HTTP Server或WebServer。
我们将在以后的文章中讨论“如何使用Express JS模块开发WebServer”。Express JS Framework provides the following features
Express JS Framework提供以下功能
NOTE:-
Node JS: HTTP Module is basic module to develop HTTP based Networking applications. Node JS: Connect Module is developed on top of HTTP module to provide some extract features like Cookies, Middleware,CSRF etc. Node JS: Express module is developed on top of “Connect” module to provide some more additional features on top of HTTP and Connect Modules.注意:-
节点JS:HTTP模块是用于开发基于HTTP的网络应用程序的基本模块。 节点JS:连接模块是在HTTP模块的基础上开发的,以提供一些提取功能,例如Cookies,中间件,CSRF等。节点JS:快速模块是在“连接”模块的基础上开发的,以在HTTP和HTTP的基础上提供更多的附加功能。连接模块。Unlike some Node JS Default Modules like “npm”,”http”,”events” come with Node JS Platform basic installation (No need of separate steps to install these modules), Express JS does not come with as Node JS Default modules. We need to install it manually.
与某些节点JS默认模块(例如“ npm”,“ http”,“事件”)随Node JS Platform基本安装(不需要单独的步骤来安装这些模块)一起提供时,Express JS并不作为Node JS Default模块附带。 我们需要手动安装。
We have already discussed on “How to install a Node JS Module” using “node install” command. If you are not familiar about this command, please go through my previous post :
我们已经使用“ node install”命令讨论了“如何安装Node JS模块”。 如果您不熟悉此命令,请阅读我以前的文章:
To install Express JS globally
Before staring Express JS Development, first and fore most step We need to do is use “npm install” command to install Express JS module全局安装Express JS
在开始Express JS开发之前,首先要做的第一步是使用“ npm install”命令安装Express JS模块。npm install -g express
Here “express” means Express JS Module and “-g” means install Express JS Module globally.
这里的“ express”表示Express JS模块,“-g”表示全局安装Express JS模块。
Open command prompt and execute above command to install Express JS Module globally.
打开命令提示符并执行上述命令以全局安装Express JS模块。
To verify installation
验证安装
After Express JS installation is done, we need to check whether this module is installed successfully or not. If it is installed successfully, we can find a new folder at
C:\Users\[Windows_USerName]\AppData\Roaming\npm\node_modules\expressExpress JS安装完成后,我们需要检查此模块是否已成功安装。 如果安装成功,我们可以在以下位置找到一个新文件夹
C:\ Users \ [Windows_USerName] \ AppData \ Roaming \ npm \ node_modules \ expressHere we are able to see “express” folder under “node_modules” folder. That means our Express JS is installed successfully.
在这里,我们可以看到“ node_modules”文件夹下的“ express”文件夹。 这意味着我们的Express JS已成功安装。
Node JS Platform has another module : “express-generator”. Earlier “express-generator” module is part of “express” module only. But to provide clear modularity, they have separated into two modules.
Node JS平台还有另一个模块:“ express-generator”。 较早的“ express-generator”模块仅是“ express”模块的一部分。 但是为了提供明确的模块化,它们已分为两个模块。
Like Express JS, Express Generator is also a Node JS Module. It is used to quick start and develop Express JS applications very easily. It does not come as part of Node JS Platform basic installation. We need to install it manually.
与Express JS一样,Express Generator也是Node JS模块。 它用于非常快速地启动和开发Express JS应用程序。 它不是Node JS Platform基本安装的一部分。 我们需要手动安装。
To install Express JS globally
Open command prompt and execute this command: npm install -g express-generator全局安装Express JS
打开命令提示符并执行以下命令:npm install -g express-generatorTo verify installation
After Express Generator installation is done, we need to check whether this module is installed successfully or not.验证安装
Express Generator安装完成后,我们需要检查此模块是否安装成功。Here we are able to see “express-generator” folder under “node_modules” folder. That means our Express Generator is installed successfully.
在这里,我们可以看到“ node_modules”文件夹下的“ express-generator”文件夹。 这意味着我们的Express Generator已成功安装。
We are going to develop simple Express JS WebApplication using Express Generator Module. We are really NOT developing this application from the scratch, just taking Express Generator help.
我们将使用Express Generator Module开发简单的Express JS WebApplication。 实际上,我们并没有从头开始开发此应用程序,只是获得Express Generator的帮助。
Please follow these steps to develop and run simple Express JS WebApplication:
请按照以下步骤开发和运行简单的Express JS WebApplication:
“express” command syntax:
“表达”命令语法:
express
Example:
例:
express ExpressSampleWebApp
If we observe this screenshot, “express” command has downloaded a sample Express JS WebApplication with given Application name. It also displays two instructions at the end of the log.
如果我们观察到此屏幕截图,则“ express”命令已下载具有给定应用程序名称的示例Express JS WebApplication。 它还在日志末尾显示两个指令。
It instructs us use “cd” command to move to our application folder and build our application by executing “npm install” command
它指示我们使用“ cd”命令移至应用程序文件夹并通过执行“ npm install”命令来构建应用程序
It instructs us set debut mode if required and execute “npm start” command to start our application.
它指示我们在需要时设置首次亮相模式,并执行“ npm start”命令来启动我们的应用程序。
Now if we access our application folder , we can see the following content.
现在,如果我们访问应用程序文件夹,我们可以看到以下内容。
To install (build) our application:
要安装(构建)我们的应用程序:
npm install
To start our Express application:
要启动我们的Express应用程序:
npm start
When we execute “npm start” command, by default it starts Express JS WebServer at 3000 port number and deploy our Express JS Application into server.
当我们执行“ npm start”命令时,默认情况下,它将以3000端口号启动Express JS WebServer,并将Express JS应用程序部署到服务器中。
It is very easy right to develop a simple Express JS WebApplication using Express Generator module. From this point, we can add our required components and code to improve this application functionality.
使用Express Generator模块开发一个简单的Express JS WebApplication非常容易。 从这一点来看,我们可以添加所需的组件和代码来改善此应用程序的功能。
Here we have developed just sample Express Application without using any Tools or IDEs. In my upcoming posts, we will discuss on “How to develop Express JS Applications using Eclipse Enide 2014 IDE”.
在这里,我们只开发了Express应用程序示例,而没有使用任何工具或IDE。 在我即将发表的帖子中,我们将讨论“如何使用Eclipse Enide 2014 IDE开发Express JS应用程序”。
That’s it about Express JS Basics. If you have queries, please drop me a comment.
就是Express JS基础。 如有疑问,请给我评论。
翻译自:
转载地址:http://nyqzd.baihongyu.com/