couchdb and node.js application deployment - node.js

I am new to couchdb and node.js. In my application I will need some server side logic and a rest api for storing and querying json documents and attachments in couchdb. Moreover, the application will provide a web console using angularjs for managing data.
What would be the best scenario for this application. Following options come to mind:
putting node.js with express in front of couchdb and serve the rest api and the console from node.js
putting couchdb in front, serving the console from couchdb as a couchapp and redirecting the rest requests through couchdb to node.js
running couchdb and node.js in parallel behind nginx reverse proxy serving the rest api from node.js and the application from couchdb
running couchdb and node.js in parallel behind nginx reverse proxy serving the rest api and the console from node.js but relaying db queries directly to couchdb
serving the console directly from nginx, relaying rest requests to node.js and db queryies to couchdb
running node.js and couchdb in parallel serving the console from either couchdb or node.js and the rest api from node.js without any reverse proxy in front of it
etc. etc.
Moreover, a general question arises:
* is it advisable to put either node.js or couchdb directly to the edge without any reverse proxy or other "wall" in front of it?
Many thanks for expert input in advance!

Related

Advise:: Does Laravel open multiple db connections on each user session?

I am communicating with a client who needs an app and backend for their company, they are a small ISP and they need a backend to monitor user usage and also an app.
So the IT Spec document that was submitted by a third party suggests using NodeJS as backend since its a single thread framework, no multiple db connections , I am used to Laravel for backend dev as so far there hasn't been any issues.
So I wanted some advise if Laravel or Node will be a better solution for this.

How to configure Angular app with ELK stack

I want to configure my Angular app with ELK stack.
Option 1:send from Angular an http post request to logstash.
Option 2: send from Angular an http post request to node.js server, and that server will send the messages to logstash.
Maybe there are another options, but i dont know. I didnt find any tutorials about it.
What is right way to do that?
Create a usable API with either REST or GraphQL or other (gRPC up to you really) to connect the client with the server, it is the most complete technique for anything wholesome.
From there you can then add more features to it and have a seed project for the future aswell.
Technically the Client sends a query to the API of your choice then the API talks with the server that the logic dictates (this can be elasticsearch / express / or any other) and then it either logs data on elastic or the DB or any other.

Building scalable SPAs using websockets, how complex is it?

I am beginner in web technologies. While studying about frontend frameworks, I came to know that we run separate application servers for frontend and backend server(API).
e.g. If I am using vue.js, I'll be running a vue server for frontend and I'll be running another MEAN stack API server separately. Now my application will need to show real-time updates, I'll have to use websocket connection between my browser and frontend server which further will need websocket/webhook connection with my backend server(API). Now I am already aware of the scalability and session management issues with websocket connection. In this scenario, how should I build my application for better scalability and with less complexity? Is it possible to create a monolithic application server for frontend and backend? Will that be a good choice?
Is it possible to create a monolithic application server for frontend and backend? Will that be a good choice?
That choice is fine; start simple and you can break into microservices in the future. Unless this is for a large production system!
If you use something like express you can serve the Vue.js files using express.static, API endpoints using express.Router() instances, and the ws or socket.io module attached to express instance for websockets.
Now my application will need to show real-time updates, I'll have to
use websocket connection between my browser and frontend server which
further will need websocket/webhook connection with my backend server
This isn't the case. You can have your frontend (the app running in a browser) connect directly to the backend via websocket if you wish, no need to proxy via a frontend server. For session management look into JWT tokens.
You can go for socket.io library in Nodejs. It's simple and easy to use, The scalability and session can be handled by introducing Redis,
check https://socket.io/docs/using-multiple-nodes/

Can a web application be developed using hybrid technologies?

Is it possible to develop a web application using a mix of technologies like servlet and nodejs? Using servlets somewhere and nodejs at some other place when required.
Yes. Read about microservices. Docker can come in handy;)
Yes, consider these two use cases.
Use case 1 (Sub Domains)
You want www.example.com to use PHP & MySQL for Wordpress, api.example.com to run on Nodejs & MongoDB and coders.example.com to use Servlets.
Here you'd code and start all servers (PHP, Nodejs & Java server) on their specific & different ports and configure a frontend server (like Nginx) to receive and redirect requests according to the subdomains specified.
Use case 2 (In-App)
You want a request to come inside your Nodejs application get processed and then trasfer data to another process (a running Java app) and wait for a response back so it can process to user.
This can be accomplished by Message ques or HTTP/web services.
Both of these services will help you share your data back and forth.
Read more on Message ques
Read more on HTTP/Web services
References
Is it possible for node.js to import a java library
https://www.quora.com/How-does-Node-js-communicate-with-Java-applications
https://www.quora.com/topic/Message-Queuing

Nginx for authentication and authorization in Node JS app

I am developing app in nodejs with expressJS and for performance optimization, I have decided to use Nginx with NodeJS (Based on my conclusion, after reading lots of articles on Nginx + NodeJS).
I have divided tasks for Nginx and NodeJS as follow :
Nginx
Serve static files
Authentication
Authorization
NodeJS
Dynamic API Handling with DB Interaction
Is it good idea to design app in above way?
If yes then how to handle authentication and authorization in Node JS app using Nginx?
If no then what is better way to handle load in NodeJS app?
Your concept is fundamentally flawed. Nginx is fast at what its meant to do, serving content over http. Putting nginx infront of node.js doesn't provide any performance improvements. Nginx can be used as a load balancer to split traffic evenly among several hosts, but in itself doesn't provide any performance benefits except for the fact that its very efficient. That said Nginx is not meant to handle authorizaton/authentication except for maybe http basic auth.
You should be writing your own logic to handle authentication and authorization. To scale you should write your code statelessly, so that you can run across multiple servers. So you should either store session data in a place such as memcache or create a stateless system using something like JWT.
Additionally, you shouldn't be serving content with node.js. Nginx is faster at this. So only serve templates with Node.js, allow Nginx to cache and serve static content. This paradigm also allows you to leverage a content distribution network. This is the only real way to leverage what nginx is good at, serving content.
Optimization isn't about making things go super fast. Optimization is something that occurs when you run into a performance barrier or need to make a system more efficient to prevent premature scaling.

Resources