Today, we cannot deny the popularity of Node.js, which exists in all fields: Micro-services, IoT (automation), Cross Platform (electron.js), etc. Besides, it is a helpful tool in modern front-end websites (Server Side Rendering, build tool – web pack, etc.). So, today’s article will briefly introduce Node.js and how to install and use this language.
What is Node.js?
When talking about that, we should talk about the following:
- Asynchronous I/O runtime
How to install Node.js?
To manage multiple versions of Node.js, we will install nvm
- Uninstall any existing versions of Node.js.
- Delete any existing Node.js installation directories (such as C:\Program Files\nodejs)
- Delete the existing npm install location (such as C:\Users\<user>\AppData\Roaming\npm)
- After this, download and run the latest stable installer, and you should be ready!
with cURL command
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
with Wget command
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
This will clone the nvm repository to ~/.nvm and make the required changes to your bash profile so that nvm is available anywhere in your terminal.
Install node version
nvm install 12.16
List all nodes installed.
Use specific node version
nvm use 12.16.2
Quick view for Node.js
Node.js is single-threaded, but in the background, it uses multiple threads to execute asynchronous code with the help of the libuv library.
It’s also event-driven, which means that everything that happens in Node is in reaction to an event.
- A new request comes in (one kind of event), and the server will start processing it.
- If it encounters a blocking I/O operation, it will register a callback before processing the next event.
- When the I/O operation has finished (another kind of event), the server will execute the callback and continue working on the original request.
What kind of Apps is Node.js suited to?
Generally, it can use in any business domain. But to be relevant to the strength of it, we need to focus on some aspects.
- Real-time interaction or Collaboration (chat, codeshare)
- API handles lots of requests that are
- I/O driven (such as those needing to perform operations on a database)
- Sites involving data streaming (Node makes it possible to process files while they’re still being uploaded)
- Simple CRUD app. (There are a lot of frameworks that support us in building CRUD app)
Besides that, we can use it in other use cases: