Node.js in Modern Web Development
Modern web development consists of building front-end applications which connect to servers to submit or get data. The front-end applications use the single-page application approach a.k.a. thick client. In it, a client app communicates with a server backend via JSON, GraphQL, Protocol Buffers, XML, text, binary streams or other formats which are transmitted via HTTP.
The server communicates with databases and other services. In other words, the server acts as a middleman between the front-end application and the database or other services. The server does things which the front-end app cannot do: authentication, data validation, working with a file system, encryption, etc.
The way the server communicates with the front-end app client and vice versa is by having various endpoints distinguished by URLs in accordance to the HTTP standard. Each request for data has URL, headers, and body (a.k.a. payload).
Implementation of servers is where Node comes in. Node is used to implement the backend servers which are often JSON RESTful APIs (but they could be of other formats as well). Node is on par with stacks such as Apache web server+PHP or Tomcat+Java.
Node is not a framework by itself because it offers very low level mechanisms. The Express framework is often used to implement web applications and RESTful API servers in Node.
Adhering to SPA and REST API architectures for your web applications will give you the flexibility to leverage your servers for other clients (mobile, IoT, public) and will allow you to change front-end clients easily because of the loose coupling provided by the API.
What is the place of Node.js in modern web development?
Let's start with a little bit of history. In 1990s, in 1995, and early 2000, the way people did web development, they were building server-side applications, and those applications they were rendering entire HTML pages. Those pages were sent to the client to the browser.
Now, their approach is similar to the thick client. We build single page applications, we build front end applications, and a lot of code resides in those applications.
On the server, we still do the validation authentication. We massage the data which is coming from the database, we format it. So, we do a lot of things on the back.
A lot of the UI and the view related logic was moved to the browser. So, this is how modern development is done right now. Some of the technologies that people use, PHP is one of the most popular platforms to build web applications.
That's a server side technology. PHP runs in a batch. Another example would be Tomcat and Java, Java, it's compiled code which would run in a Tomcat which is the web server. So typically, you need a web server and some piece of technology either compiled or interpreted. Java would be compiled and PHP would be interpreted. In Node.js it's Slightly different because Node.js combines web server and the language together.
Node.js in your stack would replace both Apache web server and PHP or both Tomcat and Java JAR file which is a compiled Java file. So, Node.js when you write Node.js code, you build a web server but also you would build your application. And what type of applications do we build? Well, most of all, we build restful API servers.
Following restful methodology, we build stateless servers. So, they shouldn't have any states within them which would make them easier to scale without the states. nd we follow the HTTP methodology by using different HTTP methods such as GET, POST, PUT etc. Another example would be building a GraphQL server.
GraphQL, it's a new emergent technology. GraphQL allows you to reduce the number of endpoints. It's still an HTTP protocol. But by reducing the number of endpoints, you can submit queries, GraphQL queries as to the server.
In all cases, Node.js will allow you to build fast performance web servers and applications as well.