Node.js Advanced Topics

  • OS
  • Process
  • Net
  • UDP
  • HTTP
  • REPL

The os module is a very nifty little module that allows us to get information about the OS.

os.arch() returns the operating system CPU architecture.

The OS module is rarely used, but now you know that it’s available if you need it.

The process object is a global that allows us to control the current process. It also has methods that can provide useful information about the process. Being an instance of the EventEmitter class, it has a few important events that we should know about.

  • process.stdin is a readable stream. We use it to read data from user input.
  • process.stdout is a writable stream. It is written to asynchronously, making it non-blocking. console.log and console.info use this stream.
  • process.stderr is also a writable stream. It is written to synchronously and, hence, is blocking. console.warn and console.error use this stream.

You can read up on more methods in the official documentation.

Understanding the workings of the net module in Node.js

  • TCP

One of the most common transport layer protocols is TCP(Transmission Control Protocol). It provides a reliable way of sending packets in an ordered and error-checked stream. TCP is connection-oriented, which means that a connection must be established between the client and the server before data can be sent.

  • UDP

Alongside TCP, UDP is the other most common communication protocol. It provides a simple and lightweight connectionless communication model. Being connectionless, a very minimal amount of protocol mechanisms come into play when sending packets. While checksums are still used for data integrity, UDP is favored in real-time applications, as it avoids the overhead of setting up a connection, error-checking, and retransmission delays.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store