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
- Handles concurrent connections efficiently due to being event-driven and non-blocking.
- Common language on both client-side and server-side
- Fuctional API
- 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.
2016-11-24 3:37 pm
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
2016-11-24 4:16 pm
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.