Node.js is a popular server-side JavaScript framework built off the impressively fast open source V8 JavaScript engine used in Google Chrome. Programs for Node.js are written in JavaScript using event-driven, asynchronous I/O requests which can help allow for handling of tens of thousands of simultaneous client connections efficiently.
Node.js is built around a server network library, and it contains built-in HTTP communication methods. So it’s possible to run a web server using just Node.js without any external software such as Apache. It also allows more control over how the web server works and it enables for an entire application, both client-side, and server-side, to be written in JavaScript.
Already know the deal on Node.js? You might want to just jump right to how to install Node.js.
Asynchronous vs Thread based requests
Common server-side programs written in languages like PHP, Python, or Perl, rely on a traditional thread based model for client connections, where each connection creates an OS thread to execute the request. These typically take around 2MB of system memory at a minimum, so if you’re on a server with 1024MB of RAM, chances are when you’re approaching around 512 simultaneous client connections to the server, you could be exhausting your server’s memory.
Node.js instead uses event-driven programming, so each connection uses a very small amount of memory while connecting. Then Node.js uses callbacks or references to inform the OS that a new connection is being requested. So the majority of the time Node.js does not disturb the OS, and this can lead to increased performance and efficiency.
No or minimal file locking
When two or more processes share the same resource from most other server-side programs, one would have to be locked temporarily in order to allocate resources to the other process. That can cause problems where essentially processes are deadlocked and battling back and forth for the required resource, leading to delays in execution.
Node.js doesn’t have this same problem as it handles almost no direct input or output operations, and so it doesn’t cause a deadlock on server resources.
What can you do with Node.js
There are a ton of different types of applications that you can build using Node.js, and while it is still a somewhat newer entry into the server-side programming realm, there are already a lot of options out there.
Here are just a few examples of the types of applications that can be built using Node.js:
- Application server
- Client of web service (FaceBook or Twitter client)
- Log and log monitoring
- Web based software
Node.js advantages
- Handles concurrent connections efficiently due to being event-driven and non-blocking.
- Common language on both client-side and server-side
- Fuctional API
Node.js disadvantages
- Can’t be run on most shared-hosting servers
- Still new and lacks some wider database support
You should now have a bit clearer picture about what Node.js is, and how it could possibly help you write more efficient server-side applications for handling large amounts of concurrent requests. In other articles, we’ll cover installing Node.js as well as some real world examples of the types of applications you can create with it.
Yeah, its a nice tutorial.
Buy I have my project in my localhost, I uploaded that.
The question is how can I put my code as a service. When the server restart the code automatically turn on.
Thanks for the answer.
Hello,
I just activated my NodeJS in my hosting.
So, The question is: How can I run my own script in the cpanel?
Please help me. Thanks
Typically you would use and access it via terminal. Here is a helpful guide I found via online search. It provides examples of some of the things you can do with node.js.
Thank you,
John-Paul