Node.js + CouchDB vs CouchDB

后端 未结 5 1728
感情败类
感情败类 2021-02-04 10:20

I\'m questioning myself why should I use combination of Node.js + CouchDB versus CouchDB standalone approach. What are the benefits of getting Node.js into the game? Any comment

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 10:55

    There is a third option: CouchDB in front, with Node.js in back...

    Traditionally, a database is on the back-end, not the front-end, so this configuration seems sort-of "backwards", but hear me out...

    In this configuration, you still serve all of your pages from CouchDB ( instead of Node ), and you use Node as a sort-of "worker process" that polls the DB for "jobs", processes them, and inserts the "results" back into the DB. This way you can use the full power of Node to do special processing, but you keep all the benefits of serving your app from the CouchDB.

    Actually, in this configuration, you could have any kind of specialized workers that run Python or Java or Ruby or whatever. For example, suppose you have a "Create-PDF" function on your website, and you want to use Python to actually create the PDFs. You simply write a python program that watches the CouchDB for any "PDF_Request" documents, processes them, and inserts the PDF files back into CouchDB. You do not have write your whole app in Python, you can just write your PDF Create function in Python, and leave the rest of your app unchanged.

    Now, suppose you replicate your CouchApp to another computer or a mobile device ( which runs CouchDB but not Node or Python ) No problem, you can still insert a "PDF_Request" into your CouchDB. When you eventually sync-up with the server, your PDF Request will then be seen and processed by the pdf creator program, and you will get your PDF File. Your couchapp still runs on the replicated CouchDB even though the "helper programs" are not there, because they are completely de-coupled from the main app.

    I am not saying that this is "the way to go", just that because of the nature of CouchDB, this configuration is actually a viable option, and will give you benefits of scaling and replication that you would not get if you put Node in front and CouchDB in back.

提交回复
热议问题