开发者

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

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.

Are there websites built completely with开发者_运维知识库 node.js? I imagine it must lack many things Rails offers.


I imagine it must lack many things Rails offers.

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.


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:

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

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:

  • session support.
  • 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.

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/

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.

authentication:

  1. Authentication and authorization (password, facebook, & more) for your node.js Connect and Express apps.
    https://github.com/bnoguchi/everyauth

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


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

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

So I think it's also good to look at Sinatra's 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.

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


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.

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

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


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.

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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜