Node notes (Beginners must-see)

. Acquaintance Node.js

What is 1.1 Node.js

  • Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
    • Node.js is not a language
    • Node.js is not a library (library), not the frame (frame)
    • == Node.js is a JavaScript runtime environment ==
    • <U> point of view is simple and can be parsed Node.js execute JavaScript code </ u>
    • == previously only browser can parse and execute JavaScript code ==
    • That is now completely off JavaScript in your browser to be run, all thanks: Node.js
    • Built on top of chrome v8 engine
      • Code strings having only a specific format
      • Engine can help you to parse and execute
      • chrome V8 engine is the resolve of workers to perform the fastest js code
      • node.js authors of Google Chrome V8 engine transplant out to develop a separate operating environment js
  • Browser JavaScript
    • ECMAscript
      • js basic grammar
    • GOOD
    • JUDGMENT
  • Node.js JavaScript in
    • No BOM, DOM
    • There ECMAScript
    • In Node JavaScript execution environment that provides some level of server operating API for JavaScript.
      • Such as reading and writing files
      • Construction of the network services
      • Telecommunication
      • http server
      • Other processing (corresponding to the web server to develop, to learn the corresponding api)
  • Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
    • event-driven event-driven
    • non-blocking I / O model nonblocking IO model (asynchronous)
    • lightweight and efficient. lightweight and efficient
    • With the course will slowly learn to understand an event-driven, non-blocking IO model
    • == NodeJS famous event-driven, asynchronous programming reached by high-performance throughput. ==
  • Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
    • npm is the world's largest open source library ecosystem
    • The vast majority of JavaScript-related packages are stored in the on npm, the purpose of doing so is to make it easier for developers to download the
    • npm is based on node.js development package management tool

1.2 == node using the API reference documentation: ==

  • Behind the black dot parameters, for example:

    • request <http.IncomingMessage>

    If the method is that it will tell you what method parameters is whether optional.

    Above requestrepresents the binding function of the parameters, because it is an event and therefore certainly need to bind a function, subsequent connections to this type of argument, what variables and methods to call the function.

  • Plus () method of representing, without () represent the properties

What do 1.3 Node.js

  • web server daemon
  • Command-line tool
    • asl
    • git (C language)
    • hexo (node)
    • 。。。
  • For front-end development engineer is concerned, the most contact node is using its command-line tool
    • Wrote very little, mainly the use of someone else posted by third parties
    • webpack
    • gulp
    • asl

1.4 achieve the goal

  • B / S programming model
    • browser-Server
    • back-end
    • Any server-side technology such BS programming model is the same, and language-independent
    • Node is a tool
  • Modular programming
    • RequireJS
    • SeaJS
    • css can be used @import('文件路径')to achieve the introduction of external files
    • Previous cognitive intelligence by js scriptto load labels
    • In Node can be like @import, like to refer JavaScript enabled file
  • Node common API
  • Asynchronous Programming
    • Callback
    • Promise
    • async
    • generator
  • Express web development framework
  • ECMAScript 6
    • In the course interspersed explain
    • It's just a new syntax
  • 。。。
  • Learn node will not only help open up the black box server, while helping to learn advanced content
    • Vue.js
    • React
    • angular

 

  • Only js file node, the code is generally .js file
  1. Create a written js file
  2. Open a terminal (command line), navigate to the script file Contents
  3. Input node 文件名execute the corresponding file, display the results

== Note: File names not be used node, it is best not to use Chinese ==

  • Parsing JavaScript execution

  • Reading and Writing Files

    • Use fsModule

      var fs = require('fs'); 
    • Read the file

      fs.readFile('路径', '可选编码', function (error, data) {});//具体查看代码 
    • The second parameter == readFile method is optional, the provisions of code resolution files, choose utf-8the encoding, let him read the page in the form of the original file, not binary data ==

    • Write file

      fs.writeFile();
      

== Node.js callback function often used as a parameter, as is asynchronous ==

  • HTTP
    • Refer to code.
    • == web page server and is generally used for communication == string, so the need to pass into json string
    • Ctrl+ cYou can turn off the server (bash and cmd as)
    • View in a browser http requests, there is a /favicon.icopath, the request is the default behavior of the browser, the purpose is requested web site Avatar
    • == response content can be a string or binary data (Buffer). Objects, numbers, arrays, Boolean == not possible, so response.end()the method can respond strings and binary data

What is modular

  • In reality, modular

    • high productivity
    • Easy maintenance, low cost
  • Modular program

    • Development of high efficiency write once, use many times
    • Easy to maintain the (lower maintenance costs) have low cohesive characteristic high coupling between the modules
  • Why use modular development approach in the program

    • Naming conflicts
    • File Dependencies

Guess you like

Origin www.cnblogs.com/att-123/p/11803022.html