NodeJs basic introduction environment configuration, built-in module

NodeJs

  • basic introduction
  • Environment configuration (node ​​nvm, cnpm)
  • REPL environment (command line) run js code
  • js file execution
  • Real-time monitoring nodemon
  • Module / package specification and commonjs
  • Internal
  • Third party
  • customize
  • Detailed built-in module
  • Url
  1. url Introduction
  2. parse
  3. format
  • Query String
  1. parse
  2. stringfly
  3. escape
  4. unescape
  • Http (reptiles)
  1. get
  2. requst
  3. cheerio
  • Event
  • Fs file operations
  • Stream

Client-side JavaScript is what

  • What is JavaScript?
    + Is a scripting language
    + running in the browser (js resolve the core browser v8)
    + implementing user interaction (interactive)
  • Analyzing logic variable assignment cycle branch target function. . . .
  • dom operation
  • bom operation
  • ajax
  • JavaScript runtime environment?
    + Browser kernel parses the kernel es6

  • What browser JavaScript can do?

  • What browser JavaScript can not do? (Unsafe)
    + access to the database
    + can not operate on the document
    + os to operate
    + because of insecurity and operational mechanism related to browser

  • In the case of the same human capacity development of programming languages ​​depends on what capacity?

+ cordova hbuilder platform Platform
+ the Java the Java virtual machine (running platform)
+ PHP PHP virtual machine
+ c # the .NET Framework Mono
+ JS parsing kernel chrome v8

  • JavaScript can only run in a browser it?
    + Not

Why is JavaScript

  • not because node js js generated
  • Select the node js
  • Ryan dahl
  • 2009 February node idea
  • 2009 May githup open source
  • 2009 November jsconf explain promote node
  • By the end of 2010 the company was acquired by xxx
  • 2018 published a major bug
  • npm (npm largest open source package manager) https://www.npmjs.com/
  • github world's largest gay dating site ( github.com ) code cloud ( gitee.com )

what is node ?

  • Node.js is a JavaScript runtime environment Chrome V8 engine king

  • Node.js uses an event-driven, non-blocking I / O model, it lightweight and efficient

  • Event-driven: tasks performed, publishers, subscribers, event-driven (on emit)

  • Non-blocking: while performing certain tasks can also perform other tasks

  • Blocking: perform a certain task, if the task is not executed, the other tasks must wait

  • Synchronize:

  • asynchronous

  • I / O: input / output (operating database, file system operations, etc.)

  • Non-blocking I / O model: When we use Node.js to achieve operational database operations, such as file system, the asynchronous operation to be carried out, the core of the traditional way to implement asynchronous operation callback function

  • Node.js package management tool npm, the world's largest repository of open source ecosystem

  • Third party: Foreign

  • Recommendation: to switch the country, the domestic Taobao mirror source

  • NRM

  • Installation cnpm

$ npm install -g cnpm --registry=https://registry.npm.taobao.org

To see if the installation was successful cnpm

cnpm -v

Environment Configuration

Node Installation

  • Installation package
  • Official website to download the corresponding installation package
  • All the way to next
  • nvm installed (there is a similar tool: nvm)
  • Node Version Manager (Node version management tool)

  • As the future development work may be tested multiple versions of Node, and Node version will be more, so we need tools to manage such funds

  • After the default installation, the default path: C: \ Users \ xxx \ AppData \ Roaming \ nvm

nvm installation tutorial blog: https://blog.csdn.net/qq_32682137/article/details/82684898

  • Question: If some students, you can not use any directory nvm, nvm only be used in the installation directory, it is the environment variable in question?

  • Advanced system variables in the environment variable creates two variables

  1. NVM_HOME
    variable name: NVM_HOME variable value: nvm installation directory path
  2. NVM_SYMLINK
    variable name: NVM_SYMLINK variable value: Node.js installation directory
  • The above path in the path variable system variables in the creation of a reference to come

;% NVM_HOME %% NVM_SYMLINK% added to the rear of the system variable pth path

Remember: Do not delete the path path

  • nvm use

nvm list List the current version of the computer all the Node.js
nvm install version Installation Node.js a version of,
for example: mounting the install 10.12.0 10.12.0 version nvm
nvm Node.js use one version Version handover
post-switching Remember: to confirm the Node output normally run
the Node -v
npm -v
If both output above normal, then switched successful
if it is not normal? In other versions to download and install (must be at least 8.9+)

The relevant version

  • node version of common sense
  • Even-numbered version is stable version (0.6.x, 0.8.x, 0.10.x)
  • Odd version of a non-stable version (0.7.x, 0.9.x, 0.11.x)
  • LTS(Long Term Support)
  • LTS and Current difference
  • Operation method:
  • Re-download the latest installation package;
  • Cover can be installed;
  • problem:
  • Previous versions of many of the global installation kit need to be reinstalled
  • You can not roll back to the previous version
  • You can not switch between multiple versions (many times we want to use a specific version)

Under Windows commonly used command line operation

  • Switch the current directory (change directory): cd
  • Create a directory (make directory): mkdir
  • View the current directory listing (directory): dir
  • Alias: ls (list)
  • Clear the current console: cls
  • Alias: clear
  • Delete files: del
  • Alias: rm

Note: All alias must use the new version of PowerShell (linux system)

computer:

cmd inside a DOS command called

wake-up terminal cmd: win key + R, type cmd Enter

Create a directory mkdir

dir lists the current directory list

cls Clear Terminal Command

del delete a file

git / powershell use the linux command

Create a directory mkdir

ls view the current directory listing

clear clear the current console

rm -rf delete a file name of a file or directory

Two types of command, cd is a meaning

common problem

  • Environment Variables loss
  • There is no need to manually configure the environment variable part of the computer after the installation is complete
  • Windows environment variables into the system and user variables
  • Environment variable variable names are not case sensitive
  • PATH variable: just add to the PATH variable, you can be in any directory
  • The purpose can be called from anywhere in the command node

Node.js monitor in real time (auto-refresh)

With third-party tools to achieve:

nodemon [ Recommended ]

cnpm i nodemon -g

nodemon file name

supervisor

cnpm i supervisor -g

supervisor file name

Guess you like

Origin blog.csdn.net/weixin_45213847/article/details/93302406