Error priority callback function
3.3
Operating system module path Path
1. The path separator different operating systems are not unified
/public/uploads/awrd
3.4 splicing path syntax
path.join ( 'path', 'path', ......)
const path = require(‘path’)、
3.5 VS absolute path relative path
Use absolute paths 1. In most cases, because the relative path sometimes the opposite of the current working directory command-line tool
2. will choose an absolute path when reading files or settings file path
3. Use --dirname get the absolute path of the current file
4. third-party modules
4.1 What is a third-party modules
Others written, with specific functions, we can directly use a module that is third-party modules, due to the third-party modules usually consist of multiple files and placed in a folder, it is called the package.
Third-party modules exist in two forms:
1. in the form of js files exist, to provide specific functions to achieve the project's API interface
2. in the form of command-line tools, project development assistance (provided command)
4.2 acquiring third-party modules
npm (node package manager): node module manages third-party tools
Download: npm install module tool
Uninstall: npm uninstall module tool
Global installation and local installation
Command-line tool: global installation
Library file: local installation
4.3 third-party modules nodemon
nodemon is a command-line tool to assist in project development.
In Node.js, each modified file must re-execute the file command line tool, very cumbersome
Steps for usage:
1.npm install nodemon -g download it
2. nodemon command at the command line tool used substitute node command js file
terminating operation ctrl + C
4.4 Third Party nrm module
nrm (npm registry manager): npm Download switcher
Steps for usage:
1.npm install nrm -g download it
2. Download the list of available queries nrm ls
3. Switch Download: nrm use Download Name
4.5 third-party modules Gulp
Build tool based on front-end node platform development
The preparation of mechanized operations into tasks, execute a command line tasks you want to perform mechanized operations can be performed automatically
Instead of manual machines, to improve development efficiency
What do 4.6 Gulp
Project on line HTML, CSS, JS file compression merger
The syntax conversion (es6, less ......)
Public files pulled
Modify the file browser automatically refresh
4.7 Gulp use
1. npm install gulp gulp download library
2. Establish gulpfile.js file in the root directory of the project
3. Reconstruction Project File folder structure of the source document placed src directory placed build the file directory dist
4. Write the task in gulpfile.js file
5. Perform gulp task command-line tool
Method of providing 4.8
1.gulp.src (): Get File tasks to be processed
2.gulp.dest (): the output file
3.gulp.task (): establish gulp task
() 4.gulp.watch: monitoring file changes
4.9 Gulp plug
gulp-htmlmin: html file compression
gulp-csso: Compression css
gulp-babel: Javascript syntax conversion of
gulp-less: less syntax conversion
gulp-uglify: Compression confuse JavaScript
gulp-file- include: public file contains
browsersync browser real-time synchronization