Usecases of NodeJS.
![]() |
Walmart and ebay. |
Node is not the best platform for CPU intensive heavy computational applications. But it is ideal for building fast and scalable network applications.
NodeJS is capable of handling a huge number of simultaneous connections with high throughput. For each connection NodeJS does not spawn new Thread causing max out of memory instead handle all in single thread using non-blocking I/O model. Using this architecture NodeJS has achieved over 1 Million concurrent connections. Bubbling errors up to NodeJS core event loop will cause crashing the entire program.
![]() |
Netflix and Uber. |
Modules in NodeJS.
In order a design to be reliable and maintainable should avoid defining variables and functions in the global scope. Instead we can use modularity. Modules or small building blocks are created where the variables and functions are defined. Therefore by using modules two variable or functions with same name will not override another function or variable defined somewhere else, because it is encapsulated inside the module.
Every file in Node application is considered as modules. Functions or variables defined in that module is the scope. In OOP it is known as private and not available outside the container/module. If you need to use the variables outside the modules ,modules must be explicitly exported for use.
[ Modules are JavaScript libraries. In other words simple or complex functionality organized in single or multiple files which can be reused throughout the Node.js application.]
![]() |
Properties of module. |
require() function.
To load or include a module we can use the 'require()' function with the name of the module. Now the application can access the HTTP module, and is able to create a server.
![]() |
Using 'require()' |
Like wise to access ,
HTTP service => 'http'
file system => 'fs'
operating system => 'os'
to get the path => 'path' etc...
Node Package Manager(npm).
- Reusable NodeJS components easily available through online repository.
- Build in version and dependency management.
- Build in scripting mechanism.
- Global installations will be available throughout the system while local installations will only be available for that particular application.
- By default all the dependencies will get installed to ‘node_modules’ directory.
- ‘package.json’ contains all information related to the NodeJS application. The file be placed in the root directory of the application.
- ‘package.json’ will contain name, version, author, repository, required node version, scripts and dependencies
Comments
Post a Comment