javascript Node.js 是构建完整网站的好选择吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6404555/
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-10-25 20:33:30  来源:igfitidea点击:

Is Node.js a good alternative to build complete websites?

javascriptruby-on-rails-3node.jsexpress

提问by donald

I'm wondering if using Node.js (express.js) is the best option to go for a complete website. I've been using Rails + Node.js and am wondering if this is still the best option or if I should move completely to Node.js.

我想知道使用 Node.js (express.js) 是否是获取完整网站的最佳选择。我一直在使用 Rails + Node.js,想知道这是否仍然是最好的选择,或者我是否应该完全转向 Node.js。

Are there websites built completely with node.js? I imagine it must lack many things Rails offers.

是否有完全使用 node.js 构建的网站?我想它肯定缺少 Rails 提供的很多东西。

采纳答案by generalhenry

Express.js is more akin to Sinatra. They're simpler frameworks than rails.

Express.js 更类似于 Sinatra。它们是比 Rails 更简单的框架。

Express's list of sites is fairly small http://expressjs.com/applications.html

Express 的站点列表相当小http://expressjs.com/applications.html

So I think it's also good to look at Sinatra's list http://www.sinatrarb.com/wild.html

所以我觉得看Sinatra的list也不错http://www.sinatrarb.com/wild.html

So to answer your questions in reverse order. Yes it lacks all the features of rails. Yes there are sites written completely in Express. And going to 100% Node.js might be the right decision for your site.

所以以相反的顺序回答你的问题。是的,它缺少 Rails 的所有功能。是的,有些网站完全用 Express 编写。100% 使用 Node.js 可能是您网站的正确决定。

It depends on which features you'd miss and what performance you need.

这取决于您会错过哪些功能以及您需要什么性能。

回答by Alfred

I imagine it must lack many things Rails offers.

我想它肯定缺少 Rails 提供的很多东西。

I gave a short list below but I would like to know what you could be missing and I think(almost certain) we can give you some alternatives on node.js.

我在下面给出了一个简短的列表,但我想知道您可能遗漏了什么,我认为(几乎可以肯定)我们可以在 node.js 上为您提供一些替代方案。



Modules

模块

node.js is getting pretty complete and I think you can run your entire site using only node.js using for example the following modules. I assume you know about npm. If not I really advice you to google for it and learn that. To search npm you can use http://search.npmjs.org:

node.js 变得非常完整,我认为您可以仅使用 node.js 运行整个站点,例如使用以下模块。我假设你知道npm。如果不是,我真的建议你谷歌搜索并学习。要搜索 npm,您可以使用http://search.npmjs.org

web framework:

网络框架:

  1. High performance, high class web development for Node.js
    https://github.com/visionmedia/express

  2. Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. https://github.com/learnboost/socket.io-node

  1. Node.js 的高性能、高级 Web 开发
    https://github.com/visionmedia/express

  2. Socket.IO 旨在使每个浏览器和移动设备中的实时应用程序成为可能,模糊不同传输机制之间的差异。 https://github.com/learnboost/socket.io-node

I believe with these two web-frameworks you can create a lot of sites. For example express is a very powerfull web framework and supports a lot of cool things like:

我相信使用这两个网络框架您可以创建很多站点。例如 express 是一个非常强大的 web 框架,支持很多很酷的东西,比如:

  • sessionsupport.
  • a lot powerful template engines. I like Jade for example. You could also share these between client and server a lot of the times easily.
  • excellent routing.
  • 会话支持。
  • 很多强大的模板引擎。例如,我喜欢 Jade。您还可以轻松地在客户端和服务器之间多次共享这些内容。
  • 优秀的路由

just to name a few.

仅举几个。

database:

数据库:

  1. Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
    https://github.com/mranney/node_redis

  2. MongoDB (from "humongous") is a scalable, high-performance, open source, document-oriented database. Mongoose is a MongoDB object modeling tool designed to work in an asychronous environment.
    https://github.com/learnboost/mongoose/

  1. Redis 是一个开源的高级键值存储。它通常被称为数据结构服务器,因为键可以包含字符串、散列、列表、集合和排序集合。
    https://github.com/mranney/node_redis

  2. MongoDB(来自“humongous”)是一个可扩展、高性能、开源、面向文档的数据库。Mongoose 是一个 MongoDB 对象建模工具,旨在在异步环境中工作。
    https://github.com/learnboost/mongoose/

With those two databases I think you should be able to accomplish most of your tasks. The nice thing is that Redis is extremely fast/simple advanced KV-store(dataset in memory/also supports VM) and supports replication while Mongodb is more completely(slower then redis) and also supports sharding.

使用这两个数据库,我认为您应该能够完成大部分任务。好消息是Redis是非常快速/简单的高级KV存储(内存中的数据集/也支持VM)并支持复制,而Mongodb更完整(比redis慢)并且还支持分片。

authentication:

验证:

  1. Authentication and authorization (password, facebook, & more) for your node.js Connect and Express apps.
    https://github.com/bnoguchi/everyauth
  1. 您的 node.js Connect 和 Express 应用程序的身份验证和授权(密码、facebook 等)。
    https://github.com/bnoguchi/everyauth

Like I said previously you can get a long way with only these modules.

就像我之前说的,你可以只使用这些模块。

回答by KooiInc

I'm not sure, but I guess it's perfectly possible. I have built complete sites using plain server side javascript for years without problems. The advantage of node.js seems to be its event driven model and things like socket.io. I just started experimenting with it, I'll probably will try porting an existing site to node.js.

我不确定,但我想这是完全可能的。多年来,我使用普通服务器端 javascript 构建了完整的站点,没有出现任何问题。node.js 的优势似乎是它的事件驱动模型和 socket.io 之类的东西。我刚刚开始尝试它,我可能会尝试将现有站点移植到 node.js。

Here you can find a large listof sites built with node.js.

在这里您可以找到大量使用 node.js 构建的站点列表

Finally, you may want to read: What it's like building a real website in Node.js

最后,您可能想阅读:在 Node.js 中构建真正的网站是什么感觉

回答by Peter Lyons

Yes, as of now node.js lacks many (well, at least a few) things rails offers. Eventually the set of available node.js modules will collectively provide good alternatives to RoR across the board. Or at least different (and often more modern) approaches to the same fundamental problems. There are still some important things missing in the node.js ecosystem including a good ORM for postgresql (rails has ActiveRecord which is great) and a good DB schema management subsystem. Both of these do not exist in the node.js ecosystem as of this moment, but surely they will be there in due time. Rails has these down pat right now.

是的,目前 node.js 缺少 Rails 提供的很多(好吧,至少是一些)东西。最终,可用的 node.js 模块集将共同为 RoR 提供全面的良好替代方案。或者至少对相同的基本问题采取不同的(通常是更现代的)方法。node.js 生态系统中仍然缺少一些重要的东西,包括一个很好的 postgresql ORM(rails 有 ActiveRecord,这很棒)和一个好的 DB 模式管理子系统。目前这两个都不存在于 node.js 生态系统中,但肯定会在适当的时候出现。Rails 现在有这些功能。

There are some tricks node.js has that RoR doesn't. Debugging in node.js is more seamless than RoR and express.js is more flexible. Express is the library approach (you tell it what to do) whereas rails is the framework approach (you fill out the boilerplate it creates for you). There are also some fantastic things like stylus and jade, which have equivalents in rails, but when you have a full app written in one language (either javascript or CoffeeScript, which I prefer) and everything is in a modern node.js/TJ Holowaychuck style, you get a level of cohesiveness that is really nice to work within.

node.js 有一些 RoR 没有的技巧。node.js 中的调试比 RoR 更无缝,express.js 更灵活。Express 是库方法(你告诉它做什么),而 rails 是框架方法(你填写它为你创建的样板)。还有一些很棒的东西,比如 stylus 和 jade,它们在 rails 中有等价物,但是当你有一个用一种语言(javascript 或 CoffeeScript,我更喜欢)编写的完整应用程序并且一切都在现代 node.js/TJ Holowaychuck 中风格,你会获得一定程度的凝聚力,在其中工作非常好。

The other thing to keep in mind is that while the list of available node.js modules is quite impressive, many of them are not as mature and battle-tested as their rails/django analogs. It's hit or miss, so beware.

另一件要记住的事情是,虽然可用的 node.js 模块列表令人印象深刻,但其中许多并不像它们的 rails/django 类似物那样成熟和经过实战测试。它是命中还是未命中,所以要小心。