Nodejs 1. First introduction

Zero, article directory

Nodejs 1. First introduction

1. First introduction to Node.js

(1) Review and reflection
  • Components of JavaScript in the Browser

image-20230608151911350

  • Why JavaScript can be executed in the browser

image-20230608152009139

  • Why JavaScript can manipulate DOM and BOM

image-20230608152549506

  • JavaScript runtime environment in the browser

image-20230608152633363

  • Can JavaScript be used for back-end development?

image-20230608152746385

(2) Introduction to Node.js
  • What is Node.js

  • JavaScript runtime environment in Node.js

  • 浏览器This is JavaScript前端运行环境.

  • Node.jsThis is JavaScript后端运行环境.

  • Node.js无法调用 DOM 和 BOM 等浏览器内位API.

image-20230608153115884

  • What Node.js can do: As a JavaScript running environment, Node.js only provides basic functions and APIs. However, based on the basic capabilities provided by Node.js, many powerful tools and frameworks have sprung up in endlessly. Therefore, learning Node.js can make front-end programmers qualified for more jobs and positions:

    • Based on the Express framework (http://www.expressjs.com.cn/), you can quickly build web applications
    • Based on the Electron framework (https://electronjs.org/), cross-platform desktop applications can be built
    • Based on the restify framework (http://restify.com/), API interface projects can be quickly built
    • Read, write and operate databases, create practical command line tools to assist front-end development, etc...
  • How to learn Node.js

    • JavaScript learning path in the browser: JavaScript basic syntax + browser built-in API (DOM + BOM) + third-party libraries (jQuery, art-template, etc.)
    • Node.js learning path: JavaScript 基础语法 + Node.js 内置 API 模块 (fs, path, http, etc.) + 第三方 API 模块 ( express, mysql, etc.)
(3) Node.js installation

image-20230615141941662

  • Distinguish the difference betweenLTS version andCurrent version

    • LTS: Long-term stable version. For 追求稳定性的企业级项目, it is recommended to install the LTS version of Node.js.
    • Current: Early adopter version of new features. For users of 热衷于尝试新特性, it is recommended to install the Current version of Node.js. However, there may be hidden bugs or security vulnerabilities in the Current version, so using the Current version of Node.js in enterprise-level projects is not recommended.
  • Window installation:

    • **Double-click installation:** Double-click the downloaded exe program to install it.

    • **Verify installation:**Open the terminal, enter the command node –v in the terminal, and press the Enter key to view the version number of the installed Node.js.

    image-20230608165203529

  • Linux installation

    [root@bluecusliyou ~]# cd /usr/local
    [root@bluecusliyou local]# mkdir nodejs
    [root@bluecusliyou local]# cd nodejs
    
    • Download the installation package to the folder
    [root@bluecusliyou nodejs]# wget https://nodejs.org/download/release/v16.20.0/node-v16.20.0-linux-x64.tar.xz
    
    • Unzip the compressed package
    [root@bluecusliyou nodejs]# tar -xvf node-v16.20.0-linux-x64.tar.xz
    [root@bluecusliyou nodejs]# ls
    node-v16.20.0-linux-x64  node-v16.20.0-linux-x64.tar.xz
    
    • Establish a soft connection so that the command can be run globally
    [root@bluecusliyou nodejs]# ln -s /usr/local/nodejs/node-v16.20.0-linux-x64/bin/node /usr/local/bin
    [root@bluecusliyou nodejs]# ln -s /usr/local/nodejs/node-v16.20.0-linux-x64/bin/npm /usr/local/bin
    
    • Verify installation
    [root@bluecusliyou nodejs]# node -v
    v16.20.0
    [root@bluecusliyou nodejs]# npm -v
    8.19.4
    
  • what is terminal

    • Terminal (English: Terminal): It is specially designed for developers as a way to achieve human-computer interaction.
    • Open the terminal in Windows system: shortcut key (Windows徽标键 + R) to open the run panel, enter cmd 后直接回车 to open the terminal.
    • In the powershell or cmd terminal of Windows, we can use the following shortcut keys to improve the operating efficiency of the terminal:
      • Use key to quickly locate the last executed command
      • Use tab key to quickly complete the path
      • Use esc key to quickly clear the currently entered commands
      • Enter cls command to clear the terminal
(4) Node.js executes JavaScript
  • Open terminal
  • enter:node app.js

Guess you like

Origin blog.csdn.net/liyou123456789/article/details/131240626