本文介绍了var app = express()有什么用?在创建Node.Js应用程序的过程中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Node.js.的新手。我正在尝试通过一个例子来学习。我在app.js中遇到了以下语句。

I am new to the world of Node.js.I am trying to learn through an example.I have encountered the following statements in the "app.js" .

  var express = require("express");----->1
  var app = express(); --------->2 

所以我理解第一个声明是加载表达模块。第二个语句需要什么?

So I understand the first statement is to load express module .What is the need for second statement??

为了在我的app.js中加载MYSQL模块,我们使用

Inorder to load a MYSQL module in my app.js we use

 var mysql = require("MYSQL");

我们通过mysql.connect()等访问SQL属性。

We access SQL properties by mysql.connect("") etc.

为什么我们不能写express.get()而不是app.get()????

so why cannot we write "express.get()" instead of "app.get()"????

为什么呢我们需要var express = require(express); ??

Why do we need var express = require("express");??

任何帮助都将受到高度赞赏。

Any help would be highly appreciated.

推荐答案

express 是一个可用于创建多个应用程序的模块。

express is a module that can be used to create more than one application.

var ex = require('express')

将此模块放入变量 ex 。获得对模块的引用后,可以使用它来创建应用程序。每个模块都有自己的API。根据expressjs文档 - ,该模块实际上是一个可用于创建应用程序的函数

puts this module into the variable ex. Once you have a reference to the module, you can use it to create application. Each module has its own API. According to the expressjs documentation - http://expressjs.com/en/4x/api.html, the module is in fact a function that can be used to create applications

var app1 = ex();
var app2 = ex();

例如,您可以想要在不同的端口上监听多个Web应用程序。

you could for example want to have several web applications listening on different ports.

如果您只想要一个应用程序(但它的可读性较差),您可以写

If you only want one application (but it would be less readable) you could write

var app = require('express')();

这篇关于var app = express()有什么用?在创建Node.Js应用程序的过程中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:24