node.js Express.js 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12616153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:22:02  来源:igfitidea点击:

What is Express.js?

node.jsexpressredis

提问by vinod

I am a learner in Node.js.

我是Node.js的学习者。

  1. What is Express.js?
  2. What is the purpose of it with Node.js?
  3. Why do we actually need Express.js? How it is useful for us to use with Node.js?
  4. What is Redis? Does it come with Express.js?
  1. 什么是Express.js
  2. 它与 Node.js 的目的是什么?
  3. 为什么我们实际上需要 Express.js?与 Node.js 一起使用对我们有什么用处?
  4. 什么是Redis?它与 Express.js 一起提供吗?

采纳答案by chovy

This is over simplifying it, but Express.jsis to Node.jswhat Ruby on Railsor Sinatrais to Ruby.

这过于简化了,但是Express.js 之Node.js就像Ruby on RailsSinatra 之Ruby

Express 3.x is a light-weight web application framework to help organize your web application into an MVC architecture on the server side. You can use a variety of choices for your templating language (like EJS, Jade, and Dust.js).

Express 3.x 是一个轻量级的 Web 应用程序框架,可帮助将您的 Web 应用程序组织到服务器端的 MVC 架构中。您可以为模板语言使用多种选择(例如EJSJadeDust.js)。

You can then use a database like MongoDBwith Mongoose(for modeling) to provide a backend for your Node.js application. Express.js basically helps you manage everything, from routes, to handling requests and views.

然后,您可以将MongoDB 之类的数据库与Mongoose(用于建模)一起使用,为您的 Node.js 应用程序提供后端。Express.js 基本上可以帮助您管理一切,从路由到处理请求和视图。

Redis is a key/value store -- commonly used for sessions and caching in Node.js applications. You can do a lot more with it, but that's what I'm using it for. I use MongoDB for more complex relationships, like line-item <-> order <-> user relationships. There are modules (most notably connect-redis) that will work with Express.js. You will need to install the Redisdatabase on your server.

Redis 是一个键/值存储——通常用于 Node.js 应用程序中的会话和缓存。你可以用它做更多的事情,但这就是我用它的目的。我将 MongoDB 用于更复杂的关系,例如 line-item <-> order <-> 用户关系。有一些模块(最著名的是 connect-redis)可以与 Express.js 一起使用。您需要在服务器上安装Redis数据库。

Here is a link to the Express 3.x guide: https://expressjs.com/en/3x/api.html

这是 Express 3.x 指南的链接:https: //expressjs.com/en/3x/api.html

回答by Azat

1) What is Express.js?

1) Express.js 是什么?

Express.jsis a Node.jsframework. It's the most popular framework as of now (the most starred on NPM).

Express.js是一个Node.js框架。它是目前最流行的框架(NPM 上最受关注的框架)。

Enter image description here.

在此处输入图片说明.

It's built around configuration and granular simplicity of Connect middleware. Some people compare Express.js to Ruby Sinatravs. the bulky and opinionated Ruby on Rails.

它围绕 Connect 中间件的配置和细粒度的简单性而构建。有些人将 Express.js 与Ruby Sinatra与笨重且固执己见的Ruby on Rails 进行比较

2) What is the purpose of it with Node.js?

2) 它与 Node.js 的目的是什么?

That you don't have to repeat same code over and over again. Node.js is a low-level I/Omechanism which has an HTTP module. If you just use an HTTP module, a lot of work like parsing the payload, cookies, storing sessions (in memory or in Redis), selecting the right route pattern based on regular expressionswill haveto be re-implemented. With Express.js, it is just there for you to use.

您不必一遍又一遍地重复相同的代码。Node.js 是一种具有 HTTP 模块的低级I/O机制。如果你只是使用一个HTTP模块,很像解析有效载荷,饼干的工作,存储会话(在内存或Redis的),选择基础上,对路由模式正则表达式必须重新执行。有了 Express.js,您就可以使用它。

3) Why do we actually need Express.js? How it is useful for us to use with Node.js?

3) 为什么我们真的需要 Express.js?与 Node.js 一起使用对我们有什么用处?

The first answer should answer your question. If no, then try to write a small RESTAPI server in plain Node.js (that is, using only core modules) and then in Express.js. The latter will take you 5-10x less time and lines of code.

第一个答案应该回答你的问题。如果不是,那么尝试在普通 Node.js(即仅使用核心模块)中编写一个小型RESTAPI 服务器,然后在 Express.js 中编写。后者将花费您 5-10 倍的时间和代码行。

What is Redis? Does it come with Express.js?

什么是Redis?它与 Express.js 一起提供吗?

Redis is a fast persistent key-value storage. You can optionally use it for storing sessions with Express.js, but you don't need to. By default, Express.js has memory storage for sessions. Redis also can be use for queueing jobs, for example, email jobs.

Redis 是一种快速持久的键值存储。您可以选择使用它来存储 Express.js 的会话,但您不需要这样做。默认情况下,Express.js 具有用于会话的内存存储。Redis 还可用于排队作业,例如电子邮件作业。

Check out my tutorial on REST API server with Express.js.

使用 Express.js查看我关于 REST API 服务器的教程

MVC but not by itself

MVC 但不是它本身

Express.js is notan model-view-controller framework by itself. You need to bring your own object-relational mapping libraries such as Mongoose for MongoDB, Sequelize (http://sequelizejs.com) for SQL databases, Waterline (https://github.com/balderdashy/waterline) for many databases into the stack.

Express.js 本身并不是一个模型-视图-控制器框架。您需要将自己的对象关系映射库,例如用于 MongoDB 的 Mongoose、用于 SQL 数据库的Sequelize ( http://sequelizejs.com)、用于许多数据库的Waterline ( https://github.com/balderdashy/waterline) 放入堆。

Alternatives

备择方案

Other Node.js frameworks to consider (https://www.quora.com/Node-js/Which-Node-js-framework-is-best-for-building-a-RESTful-API):

要考虑的其他 Node.js 框架(https://www.quora.com/Node-js/Which-Node-js-framework-is-best-for-building-a-RESTful-API):

UPDATE: I put together this resource that aid people in choosing Node.js frameworks: http://nodeframework.com

更新:我整理了这个帮助人们选择 Node.js 框架的资源:http: //nodeframework.com

UPDATE2: We added some GitHub stats to nodeframework.com so now you can compare the level of social proof (GitHub stars) for 30+ frameworks on one page.

更新 2:我们向 nodeframework.com 添加了一些 GitHub 统计数据,因此现在您可以在一页上比较 30 多个框架的社交证明(GitHub 星)级别。

enter image description here

在此处输入图片说明

Full-stack:

全栈:

Just REST API:

只是 REST API:

Ruby on Rails like:

Ruby on Rails 像:

Sinatra like:

西纳特拉喜欢:

Other:

其他:

Middleware:

中间件:

Static site generators:

静态站点生成器:

回答by Muhammad Shahzad

  1. What is Express.js?
  1. Express.js 是什么?

Express.js is a Node.js web application server framework, designed for building single-page, multi-page, and hybrid web applications. It is the de facto standard server framework for node.js.

Express.js 是一个 Node.js Web 应用程序服务器框架,专为构建单页、多页和混合 Web 应用程序而设计。它是 node.js 的事实上的标准服务器框架。

Frameworks built on Express.

基于 Express 构建的框架。

Several popular Node.js frameworks are built on Express:

几个流行的 Node.js 框架是基于 Express 构建的:

LoopBack: Highly-extensible, open-source Node.js framework for quickly creating dynamic end-to-end REST APIs.

Sails: MVC framework for Node.js for building practical, production-ready apps.

Kraken: Secure and scalable layer that extends Express by providing structure and convention.

MEAN: Opinionated fullstack JavaScript framework that simplifies and accelerates web application development.

LoopBack:高度可扩展的开源 Node.js 框架,用于快速创建动态的端到端 REST API。

Sails:Node.js 的 MVC 框架,用于构建实用的、生产就绪的应用程序。

Kraken:安全且可扩展的层,通过提供结构和约定来扩展 Express。

MEAN:经过深思熟虑的全栈 JavaScript 框架,可简化和加速 Web 应用程序开发。

  1. What is the purpose of it with Node.js?
  2. Why do we actually need Express.js? How it is useful for us to use with Node.js?
  1. 它与 Node.js 的目的是什么?
  2. 为什么我们实际上需要 Express.js?与 Node.js 一起使用对我们有什么用处?

Express adds dead simple routing and support for Connect middleware, allowing many extensions and useful features.

Express 添加了简单的路由和对 Connect 中间件的支持,允许许多扩展和有用的功能。

For example,

例如,

  • Want sessions? It's there
  • Want POST body / query string parsing? It's there
  • Want easy templating through jade, mustache, ejs, etc? It's there
  • Want graceful error handling that won't cause the entire server to crash?
  • 想要会话?在那
  • 想要 POST 正文/查询字符串解析?在那
  • 想要通过玉、小胡子、ejs 等轻松模板?在那
  • 想要优雅的错误处理,不会导致整个服务器崩溃?

回答by praetoriaen

  1. Express.js is a modular web framework for Node.js
  2. It is used for easier creation of web applications and services
  3. Express.js simplifies development and makes it easier to write secure, modular and fast applications. You can do all that in plain old Node.js, but some bugs can (and will) surface, including security concerns (eg. not escaping a string properly)
  4. Redis is an in-memory database system known for its fast performance. No, but you can use it with Express.js using a redis client
  1. Express.js 是 Node.js 的模块化 Web 框架
  2. 它用于更轻松地创建 Web 应用程序和服务
  3. Express.js 简化了开发并使编写安全、模块化和快速的应用程序变得更容易。您可以在普通的旧 Node.js 中完成所有这些,但一些错误可能(并且将会)浮出水面,包括安全问题(例如,没有正确转义字符串)
  4. Redis 是一种内存数据库系统,以其快速的性能而闻名。不,但您可以使用 redis 客户端将它与 Express.js 一起使用

I couldn't be more concise than this. For all your other needs and information, Google is your friend.

我不能比这更简洁了。对于您的所有其他需求和信息,Google 是您的朋友。

回答by Rishabh.IO

ExpressJS is bare-bonesweb application framework on top of NodeJS.

ExpressJS是裸机上的的NodeJS顶部Web应用程序框架。

It can be used to build WebApps, RESTFUL APIs etc quickly.

它可用于快速构建 WebApp、RESTFUL API 等。

Supports multiple template engines like Jade, EJS.

支持 Jade、EJS 等多种模板引擎。

ExpressJS keeps only a minimalist functionality as core features and as such there are no ORMs or DBs supported as default. But with a little effort expressjs apps can be integrated with different databases.

ExpressJS 仅保留一个极简的功能作为核心功能,因此默认不支持 ORM 或 DB。但是稍加努力,expressjs 应用程序就可以与不同的数据库集成。

For a getting started guide on creating ExpressJS apps, look into the following link:

有关创建 ExpressJS 应用程序的入门指南,请查看以下链接:

ExpressJS Introductory Tutorial

ExpressJS 入门教程

回答by Andrei-Cristian Ene

Express is a module framework for Node that you can use for applications that are based on server/s that will "listen" for any input/connection requests from clients. When you use it in Node, it is just saying that you are requesting the use of the built-in Express file from your Node modules.

Express 是 Node 的模块框架,可用于基于服务器的应用程序,这些应用程序将“监听”来自客户端的任何输入/连接请求。当您在 Node 中使用它时,它只是说您正在请求使用来自您的 Node 模块的内置 Express 文件。

Express is the "backbone" of a lot of Web Apps that have their back end in NodeJS. From what I know, its primary asset being the providence of a routing system that handles the services of "interaction" between 2 hosts. There are plenty of alternatives for it, such as Sails.

Express 是许多后端在 NodeJS 中的 Web 应用程序的“支柱”。据我所知,它的主要资产是处理两台主机之间“交互”服务的路由系统的天意。它有很多替代方案,例如 Sails。

回答by Frostiy

Express.js is a framework used for Node and it is most commonly used as a web application for node js.

Express.js 是用于 Node 的框架,它最常用作 Node js 的 Web 应用程序。

Here is a link to a video on how to quickly set up a node app with express https://www.youtube.com/watch?v=QEcuSSnqvck

这是有关如何使用 express https://www.youtube.com/watch?v=QEcuSSnqvck快速设置节点应用程序的视频链接

回答by Rashi Goyal

Express.js created by TJ Holowaychuk and now managed by the community. It is one of the most popular frameworks in the node.js. Express can also be used to develop various products such as web applications or RESTful API.For more information please read on the expressjs.com official site.

Express.js 由 TJ Holowaychuk 创建,现在由社区管理。它是 node.js 中最流行的框架之一。Express 还可以用于开发各种产品,例如 Web 应用程序或 RESTful API。更多信息请阅读 expressjs.com 官方网站。