Communicate between a Rails app and a Node.js app

前端 未结 5 2122
长情又很酷
长情又很酷 2021-02-13 14:41

This question follows a previous one: Shall I use Node.js Instead of Rails for Real-time WebApps?

The question:

What\'s the best way of communic

5条回答
  •  生来不讨喜
    2021-02-13 15:17

    Why do the apps need to communicate?

    If you simply need a Rails app to get some realtime data into the browser, then using a node.js server app and Socket.IO would be sufficient.

    You have to remember that any Rails apps, is actually two applications, one written in Ruby running on the server, and one written in Javascript running on the client. They usually communicate over HTTP, sometimes with AJAX and sometimes not. Which part of your app needs the functionality of node.js?

    If it is the case that the app deals with login, then displays a web page, and then continually refreshes that web page with real-time data, you only really get a benefit from node.js for the realtime data refreshes whether you do it with AJAX polling or with Websockets. Shared databases are a nice way for apps to communicate, but not for realtime.

    To make it clear, if you are an expert in Ruby with Rails, you will be more productive if you add a node,js server app and only use it for high-volume data, such as realtime updates. You then have a hybrid web app that leverages the best of both platforms.

提交回复
热议问题