What is Node.js?
When to use Node?
Node is great for streaming or event based real-time applications like Chat Applications, Game Servers, Ad Servers and Streaming Servers. Node is great when you want high levels of concurrency with little dedicated CPU time. You can install Node on Windows from here. make sure node executable has been added to your PATH system environment variable. To create Node js projects in Visual Studio 2015 get the Node.js tools for Visual Studio from here.
The solution structure for console application looks as following
Lets say you want to make a basic HTTP Server that will then send Hello World plain text to our browser. You can do by writing the following few lines of code in app.js file
for example if you want to read a file then you need a require module and the name of the moduleÂ is fs. This is synchronous file reading
same piece of code can be written in asynchronous mode as below
for example if you want to create a socket then you can write the following code
Now a client can make a connection to your socket and get the information from server
Basically in order to load a module in node js you use require function with the path of the file or directory containing the module that you would want to load. It then returns a variable which contains all exported functions. Official package manager for node is NPM. when you use npm command it installs all dependencies automatically with the environment. To install a package you can use
npm install â€“ package_name
when you install a package using npm then it installs the packages locally in a folder nodes in your project.packages.json file contains all the dependencies that you are using in your application.The contents of packages.json looks as below
some of the popular Node modules are