Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries that makes development on nodejs quick and easy.
console.log('My first NodeJS code');
When the above code is saved as a file - index.js - the file can be executed from the command line (windows) as shown below.
> rem note: navigate to the 'index.js' folder in command line > node index.js > rem can also be run in the following way > node index
It is interesting that NodeJS is fast even though it is single threaded. Below are the characteristics of NodeJS.
NodeJS is single threaded and never spawns on other threads. This makes it easy for developers to build application using NodeJS as they do not need to deal with concurrency. Even after running on a single thread, NodeJS runs fast and is highly scalable due to its non blocking IO model.
NodeJS is event driven meaning that it responds when something happens by running the necessary code and on other times it simply waits leaving the CPU free.
In NodeJS, the execution does not stop for I/O requests and this is the main reason for its scalability. This means that when a file is read and database query is run, the execution does not stop and keeps processing the following code. The I/O calls register a callback which is executed when the actual I/O requests complete.