Overview of Node development
1.1 Why learn the basics of server-side development
Be able to work more closely with back-end programmers
Website business logic in front, learning front-end technology needs back-end technology support (Ajax)
Broaden your knowledge horizon and look at the whole project from a higher perspective
1.2 Things to do in server-side development
Implement the business logic of the website
Add, delete, change and check data
1.3 Why Choose Node
①Node is a platform based on the Chrome JavaScript runtime, for easy to build, fast response, easy to web applications extension.
② As web front-end developers need to understand a background language
③ NodeJS is easier to use for front-end developers
1.4 What is a Node
Node is a JavaScript environment based on the Chrome V8 engine.
Runtime environment
The browser (software) can run JavaScript code, and the browser is the environment in which JavaScript code runs >Node (software) can run JavaScript code
2.Node running environment construction
2.1 Installing the Node.js Operating environment
Liverpoolfc.tv: nodejs.org/en/
LTS = Long Term Support Stable version Current Has the latest feature experimental version
2.2 Solution to Node Environment Installation Failure
1. Error code 2502, 2503
Cause: The system account has insufficient permissions.
Solution: Run the powershell command line tool as an administrator and run the msiexec /package node command to locate the installation package
2. An error occurs when the command is executed
Cause: The Node installation directory fails to write environment variables
Workaround: Add the Node installation directory to the environment variable
2.3 PATH Environment Variable
Directories in the storage system. When you run a command on the cli, the system automatically searches for the command location in these directories.
Quick start with Node.js
3.1 Composition of Node.js
JavaScript consists of three parts: ECMAScript, DOM, and BOM.
Node.js is made up of additional apis provided by ECMAScript and the Node environment, including files, networks, paths, and more powerful apis.
3.2 Basic Syntax of Node.js
All ECMAScript syntax is available in the Node environment.
To execute the code in the Node environment, use the Node command to execute the.js file
3.3 Node.js Global object global
In the browser the global object is window, in Node the global object is global.
Node has the following methods under global objects, which can be used anywhere. Global can be omitted.
Console.log () is printed in the console
var first = 'hello nodejs'; console.log(first); Function fn (){console.log('fn function was called '); ] } fn (); for (var i = 0; i <5; i ++) { console.log(i); } if (true){ console.log('123'); } console.log(' File has been modified ')Copy the code
SetTimeout () Sets the timeout timer
setTimeout(function (){ console.log('123'); }, 2000).Copy the code
ClearTimeout () Clears the timeout timer
SetInterval () sets the interval timer
ClearInterval () Clears the intermittent timer