Nodejs Quick Start (2)-nodejs

    NodeJS is a runtime environment that runs on the Chrome V8 engine and parses JavaScript. Its features are event-driven, non-blocking IO, lightweight, efficient, and managed based on npm.

(1) The difference between NodeJS and JavaScript

        NodeJS is a runtime environment for running and parsing JavaScript scripts, quite cloud Java to JVM.

(2) NodeJS

       ① The structure of NodeJS includes V8 JavaScript parsing engine, ECMAScript.

       ②The middle layer (providing file operations and network operations) is used by developers who are close to the interface of the operating system.

        ③Hardware layer

(3) NodeJS community

        In 2009, hosted to github as a third-party project,


(4) Installation and configuration

Download the nodejs package         from .

    

    Build the windows environment, download the .mis package, and install it in the next step.

(5) Node foundation

        ①REPL (Read-eval-print-loop)


        In fact, it is a cmd command line tool that runs javascript and runs JavaScript code.

(6) global global variable

var a = 123;

b = 456;

The difference between these two lines of code is that a global variable var a = 123 of window will be created in the browser parsing js engine; this method will give the a variable to window.

nodejs has a global variable global, which is the same as the browser parsing js to generate a window global object, but the var a variable definition method does not give a to the global gobal, because the scope of nodejs's restriction on js files is within the js file, through a The = value method can give the variable a to the global variable global.

Here are some other commonly used global variables

__dirname & __filename current folder and current file directory
setInterval() & clearInterval()
setTimeout() & clearTimeout()
console
exports & module
process
require()
Class:Buffer

(7)console

    Compared with the console in the browser environment, nodejs is enhanced.

    ①Assert console.assert(express,out); express is a conditional expression, and out is the content of the output if the expression does not hold

    ②console.time() & console.timeEnd() Calculate the running time of the two pieces of code, and the parameters passed in should be consistent.

(8)Process

    The process object provides the process information of the current node,

process.version takes the version number and
does standard output in the console
process.stdout.write(`123123`);
process.pid: the process number of the current process.
process.version: The version of Node, such as v0.10.18.
process.platform: The current system platform, such as Linux.
process.env: Points to the environment variable of the current shell, such as process.env.HOME.
process.stdout: Points to standard output.
process.stdin: Points to standard input.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325622332&siteId=291194637