What is a node. Js

Node.js is a JavaScript runtime environment based on the Chrome V8 engine that uses an event-driven, non-blocking I/O model. To put it bluntly, Node.js allows programs written in JS language to run on the server side, and provides file reading and writing, operating system and other functions.

Install the node

Rookie under https://www.runoob.com/nodejs/nodejs-install-setup.html don’t dwell on the reference document.

Run the node

  1. The base command runs node
  • Output the node XXX file in the command line of the current file.
  1. Code Runner plug-in command
  1. Nodemon content is hot updated

npm install -g nodemon

  • As you can see, re-changing the content automatically updates the content after saving it.

Global object

The Buffer Buffer

Js has no binary data type and must use binary data when processing file streams. The buff is used to create a cache dedicated to binary data.

  1. Creating a Buffer object
  1. attribute
  1. Buffer class method
  1. Buffer object method

modular

Asynchronous I/o

IO refers to Input/output in a computer.

path

  1. attribute
  1. methods

fs

  1. Obtaining File Information
  1. Read file Write file

3. Stream operation reads and writes files

6. Copy files

7. Directory operations

url

Setting up the HTTP Server

The response (res)

Response static data

Response dynamic resource

  1. In response to JSON
  1. The response HTML

Request (the req)

  1. Get
  1. Post

The path to distribute

package

1. The concept

A package is a further abstraction on a modular basis, encapsulating a separate function for release, update, dependency management, and version control. NPM is used in development to address package publishing and acquisition requirements.

  1. specification
  1. package.json

4. Create packages

npm init -y