What is a node?
It is commonly used to build applications, work with modern web app frameworks and script pages on the server side with JS. In practice, Node allows you to drive
.js files with
node command similar to how you would drive
.py files with
The node is also used to build desktop apps, using a framework called Electron. Electron powers Slack, Discord, Visual Studio Code and Skype. Basically, it runs a slim version of Chrome designed for the desktop, and the app itself is really just a web app. As a result, the Electron apps are very RAM-hungry and will work a little worse than their original counterparts, but that trade is often done for consistency across all operating systems and the web.
Node Ecosystem (npm modules)
The node itself is cool, but it would not be anywhere near it is today if it were not for
npm, Node packet manager.
npm makes it possible to extend Node with frames and plugins, and makes it easy to install and integrate code in a new project.
For example, say you are working on a script and need to send a POST request to an external resource. You can use JS’s built-in
fetch or you can use axios, which use promises and are easier to use. If you wanted to add axios to your project, move your script to its own folder and run:
npm init npm install axios
This creates a file named
package.json, which keeps track of project settings and installed packages. The
npm install command creates a folder named
node_modules, which stores downloaded modules. Warning, this folder can be very large on large projects with many modules.
To use axios in your script, add this line at the top:
const axios = require('axios');
Or in ES6 syntax:
import axios from 'axios';
This imports the module from
node_modules, and let your script access it. From there, you can use it as if it were part of your project and just another function you did.
Axios is just a basic example of a useful
npm tool. You have probably heard of other modules such as React, Angular or Vue; all of these are complete web application frameworks used to build interactive apps running in the browser. Apps built with these frameworks are commonly referred to as “Node apps.” While they do not actually run with Node, as the final product will be static HTML that you can serve with any old web server, Node is used for development and packages are installed from the Node ecosystem with
How does the node work with nginx and Apache?
The Node itself does not border directly on nginx or Apache – everything Node does runs
.js files. But Node apps built with React or other frameworks work a little differently than regular HTML pages.
With React, you basically serve a blank HTML page that loads one
One thing to note is a popular library called Express. Express serves web content and can act as an HTTP server. It is commonly used as a router to create a node-based REST API; Express can listen on a port, forward the request to another function (usually accessing another resource such as a database) and then send back an HTTP response.
In this case, you would put Express behind the nginx server you use for your static content and route all
/api routes to Express. This allows your web app to access external resources and take advantage of Node’s full server-side scripting power and the ability to interface with databases. You can use nginx as a reverse proxy for
/api route, and use it as a web server for the other static content.
In all cases, Express is not a web server. Nginx should not be included in this example. It can work as one, and it is very useful to configure a simple Express server for development, or a simple page that does not get much traffic. But it is far from the performance of nginx and Apache, which are built-in apps. If you are building a real web application, serve it with nginx and use Express just to display APIs.
Should I use the node for my site?
If you are not building a web app, you probably do not need Node. It is not intended for static pages. You for sure Can, but you will not see much benefit. If you are planning to use a complete web framework like React for a static (or even mostly static) website, you may want to consider again, as React introduces a lot of overhead on your site. React loading times are generally much slower without server-side rendering, which is good for web applications designed for long session times, but not for a blog or anything looking for good SEO. Vanilla JS can do a lot of DOM manipulation on its own, especially using jQuery.