JavaScript Node.js
JavaScript Node.js, a program that allows you to apply your JavaScript skills outside of the browser. With it, you can build anything from small command line tools to HTTP servers that power dynamic websites.
the main concepts that JavaScript Node.js uses and to give you enough information to write useful programs for it. They do not try to be a complete, or even a thorough, treatment of the platform One of the more difficult problems with writing systems that communicate over the network is managing input and output—that is, the reading and writing of data to and from the network and hard drive. Moving data around takes time, and scheduling it cleverly can make a big difference in how quickly a system responds to the user or to network requests.
In such programs, asynchronous programming is often helpful. It allows the program to send and receive data from and to multiple devices at the same time without complicated thread management and synchronization.
Node was initially conceived for the purpose of making asynchronous programming easy and convenient. JavaScript lends itself well to a system like Node. It is one of the few programming languages that does not have a built-in way to do in- and output.
Node Command
When Node.js is installed on system, it provides a program called node, which is used to run JavaScript files. Say you have a file hello.js, containing this code:
let message = "Hello world"; console.log(message);
You can then run node from the command line like this to execute the program:
$ node hello.js Hello world
The console.log method in Node does something similar to what it does in the browser. It prints out a piece of text. But in Node, the text will go to the process’s standard output stream, rather than to a browser’s JavaScript console. When running node from the command line, that means you see the logged values in your terminal.
If you run node without giving it a file, it provides you with a prompt at which you can type JavaScript code and immediately see the result.
JavaScript Node.js Example
$ node > 1 + 1 2 > [-1, -2, -3].map(Math.abs) [1, 2, 3] > process.exit(0) $
The process binding, just like the console binding, is available globally in Node. It provides various ways to inspect and manipulate the current program.
The exit method ends the process and can be given an exit status code, which tells the program that started node (in this case, the command line shell) whether the program completed successfully (code zero) or encountered an error (any other code).
Note that it also includes the name of the node command and your script name, so the actual arguments start at index 2. If showargv.js contains the statement console.log(process.argv), you could run it like this:
$ node showargv.js one --and two ["node", "/tmp/showargv.js", "one", "--and", "two"]
All the standard JavaScript global bindings, such as Array, Math, and JSON, are also present in JavaScript Node’s environment. Browser-related functionality, such as document or prompt, is not.