background: because Appium is based on node. JS, I want to look at node. js. But the order of finding a lot of data looks a bit upside down. Then on the side of the data on the side of the outline of the knowledge of the framework, I hope to be useful to others. This article does not contain the basic syntax for node. js. The basic syntax of node. JS is basically the same as JavaScript, which can be used to sort out a basic syntax later on. node. js is a chrome V8-based JavaScript runtime environmentnode. JS is an event-driven, non-blocking I/O modelnode. JS uses NPM Package Managerusing node. js not only implements an application, but also implements the entire HTTP server, so there is no need to build Apache or Nginx separately
node. JS installation
How to install under MacBrew Install node
View the version of node. JSnode-v
View package management tools NPM versionnpm-v
Interactive interpreter into node. JSnodeThe interactive interpreter is similar to Python. You can enter a command to view the input results in real time
Use of NPMNPM is installed along with nodeNPM allows users to download and install third-party packages from the NPM server, and also allows their own packages to be uploaded to third-party servers, such as Python-like Pip
NPM Installation CommandsNPM Install "package name"The installed packages are placed in the Node_modeles directory of the project directory, for example, on Mac, under the/usr/local/lib/node_modules folderThe installed package is referenced in the Code by require ("package name") The package module is installed in the directory with Package.json, the file contains the package name, the list of dependencies (NPM installation will automatically install the package in the dependency table) Package.json Property Description
name -the package name.
Version-number of the package.
Description -Description of the package.
Homepage -the website URL of the package.
author -The name of the author of the package.
Contributors -Other contributors ' names for the package.
Dependencies -List of dependent packages. If a dependent package is not installed, NPM will automatically install the dependent package in the Node_module directory.
Repository -the type of place where the package code is stored can be git or svn,git available on Github.
The main-main field is a module ID, which is a main item that points to your program. That is, if the name of your package is called Express, then the user installs it and then require ("Express").
- Keywords -keywords
http://www.runoob.com/nodejs/nodejs-npm.html(attribute transfer from novice tutorial)
npm Uninstall CommandNPM Uninstall "package name"
Update ModuleNPM Update "package name"
Search ModuleNPM Search "package name"(search for packages containing this keyword from the Package Management Center)
change NPM to download the address for the domestic warehouseSome packages are slow to download and can be switched to a domestic warehouseNPM Config list (see some of NPM's configuration items)NPM Config Set registry cnpmjs.org (change warehouse to cnpmjs.org) after the first change of the warehouse, a ~/.NPMRC file is created with the content "registry=" https://registry.npm.taobao.org ""If you want to cut back to the original Download Center, you can comment out or delete the registry in ~/.NPMRC.
node. JS introduces other modulesintroducing additional modules via require ()
third-party modules introduced with NPM downloadsrequire ("module name")
introduce a module under a local path (it is actually a. js file, no suffix is required for reference)require ("Path/module name")For example, the Hello.js module that introduces the current directory: Require ("./hello")
node. js functionsone function in node. js can receive parameters as another function, defining functions through the
keyword functiondefinition mode: function name (parameter) {What to do} function Say (word) {Console.log (word)} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ definitionSay ("hi") \ \ Call the function say and pass the parameter word as Hi when a function is passed as a parameter, you can also define an
anonymous function (without the function name, direct functions (parameters) {What to do}) passed directly to the functionfunction exe (name,value) {name (value)} \ \ \ \ \ \ \ \ \ \ \ \ \ Define an EXEexe (function (value) {Console.log (value)}, "Wow,see it!") \ \ Executes EXE (), the first parameter passed is an anonymous function
node. JS Eventsnode. JS is a single-process single-threaded application that supports concurrency through events and callbacks (node. JS All APIs are asynchronous through callbacks)all events in node. JS are implemented in the Observer patternmost of the modules in node. js are inherited from the event module (the event module is an implementation of a simple incident listener pattern) node. js can bind and listen to events by introducing the events module and instantiating the Eventemitter class.
handler functions for binding events and events: Eventemitter.on ("event name", function) \ \ is actually binding to time eventemitter a listener
Trigger Event: Eventemitter.emit ("event name") examples are as follows:var events=require ("Events")//Import Events Modulevar eventemitter=new events. Eventemitter ()//Eventemitter class for instantiation eventsEventemitter.on ("Start", function () {Console.log ("Hello World")})//Register an event, bind print Hello World event, name start, The actual start is a listener .eventemitter.emit ("Start")//Trigger event start actually on the call is AddListener (Event,listener). An event can be on multiple listeners, which executes sequentially when emit executes. you can remove a listener with removerlistener, and there are many other ways to monitor it. class Method
the callback function of node. JSall of node's APIs support callback functions (you can also choose not to use callback functions), and node. JS's async is implemented through callbacks, non-blocking I/O, which greatly improves the performance of node. JSThe blocking is executed sequentially, and the current code must be executed before the next execution. Rather than blocking is not required in order, so if you need to handle the parameters of the callback function, you need to write in the callback function. For example, the Read function of FS ReadFile:var fs=require ("FS")fs.readfile ("Test.txt", function (err,data) {if (err) return Console.log (ERR)Console.log (data.tostring ())}) The first parameter of the API callback function of node is the catch error, the second parameter is generally the correct return value
node. JS Global ObjectGlobal object: It and all its properties can be accessed anywhere in the program, without the need for require importProcess : Interact with current processes to view current directory, process, etc.console: For outputsetTimeout: Timing, usage "setTimeout (function, millisecond unit of time)" There are a lot of other global objects
node. JS Tools ModuleThere are many useful modules in the node. JS Module Library, and here are a fewOS: Returns some data from the current systempath: Some operations on the pathhttp: Can create Web server objects, etc.FS: Read and write files for the operation
node. JS's knowledge point framework collation