当前位置:网站首页>Nodejs installation and introduction
Nodejs installation and introduction
2022-06-30 19:10:00 【John is orange】
Node.js Installation and introduction
1. use nvm management node edition
In general, when studying , A version of node That's enough , You can download it directly on the official website . But in the production process , It's hard to avoid meeting node For different versions of the project , So download nvm It's a necessary thing . If it is windows user , Please use nvm-windows!
https://github.com/nvm-sh/nvm/blob/master/README.md
install :
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Add related configuration ,nvm The default location is ~/.nvm.
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
After the above two lines are run , Passing instructions nvm list You can see mvn Installed node Version list . If the installation is successful, you can display .

Install the specified node edition : For example, the large version to be installed is 16 Of , direct nvm install 16 that will do . The small version is the same nvm install 16.15.0.
Switch to another version node: Switch the large version number directly nvm use 14, You can switch to the large version 14 Of node Environmental Science , The same is true for specifying small versions .
View the currently used node edition :node -v
2. nodejs and js The difference between
- ECMAScript(ES): Defines the syntax , Write JS and nodejs Must abide by
- Variable definitions , loop , Judge , function
- Prototypes and prototype chains , Scope and closure 、 asynchronous
- Can't operate DOM, Can't monitor click Time , Can't send Ajax request
- Can't handle http request , Can't operate file
- therefore , Only ES, I can hardly do any actual projects
- JavaScript(JS): Use ES Grammatical norms , Plus Web API, Be short of one cannot .Web API Standard by W3C Regulations .
- DOM operation ,BOM operation , Time bound ,Ajax etc.
- Combination of the two , You can complete any operation on the browser side
- nodejs: Use ES Grammatical norms , Plus nodejs API.
- Handle http, Processing documents, etc
- Combination of the two , Can finish server Any operation on the end
summary
- ECMAScript It's grammar
- nodejs = ECMAScript + nodejs API
- JS = ECMAScript + WebAPI
function nodejs Method
Command line run :
node js File path
that will do , Also available vscode Plugins in Code Runner, One click operation , Save your own manual input command line .

3. commonjs
commonjs Import and export
// a.js
function add(a, b) {
return a + b;
}
function mul(a, b) {
return a * b;
}
module.exports = {
add,
mul,
};
// b.js
const {
add, mul } = require("./a");
const sum = add(10, 20);
const mulRes = mul(100, 200);
console.log(sum);
console.log(mulRes);
commonjs quote npm package
Initialization first npm Download after environment npm package
yarn init -y
yarn add lodash
And then according to npm Name reference is enough
const _ = require("lodash");
const arr = _.concat([1, 2], 3);
console.log(arr); // [1, 2, 3]
4. debugger
debugger Everyone is familiar , The code pauses at the break point , Easy to find errors .
vscode stay debug When , I'll look for package.json Of main Property , This file is the main entry , The default name is index.js.
After the break point, you can click the debugging entry on the left to start debugging .

5. server The difference between development and front-end development
Not learned nodejs It means that we can develop the back-end !
- Service stability
- server The client may suffer from various malicious attacks and misoperations
- A single client can hang up unexpectedly , But the server cannot
- Service stability application :PM2 Process daemons
- Consider memory and CPU ( Optimize , Expand )
- The client monopolizes one browser , Memory and CPU It's not a problem
- server The end has to carry many demands ,CPU And memory are scarce resources
- Use stream Write the log , Use redis save session, Optimize memory
- logging
- The front end will also participate in logging , But only the initiator of the log , Don't care about follow-up
- server The client should record the log 、 Store logs 、 Analysis log , The front end doesn't care
- Security
- server The client should be ready to receive all kinds of malicious attacks at any time , The front end is much less , Such as : Unauthorized operation , Database attacks, etc
- application : validate logon , The prevention of xss Attack and sql Inject
- Cluster and service splitting
- Fast product development , Traffic may increase rapidly
- Carry more traffic by expanding machine and service splitting
边栏推荐
猜你喜欢

Dlib library for face key point detection (openCV Implementation)

The online procurement system of the electronic components industry accurately matches the procurement demand and leverages the digital development of the electronic industry

AI首席架构师10-AICA-蓝翔 《飞桨框架设计与核心技术》

Infineon - GTM architecture -generic timer module

【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台

Swin-transformer --relative positional Bias

德国AgBB VoC有害物质测试

医疗行业企业供应链系统解决方案:实现医疗数智化供应链协同可视

20220607跌破建议零售价,GPU市场正全面走向供过于求...

Countdowncatch and completabilefuture and cyclicbarrier
随机推荐
服务器之间传文件夹,文件夹内容为空
dtd建模
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
mysql for update 死锁问题排查
Digital intelligent supplier management system solution for coal industry: data driven, supplier intelligent platform helps enterprises reduce costs and increase efficiency
Is it safe to open a mobile stock account? Is it reliable?
rust配置国内源
金融服务行业SaaS项目管理系统解决方案,助力企业挖掘更广阔的增长服务空间
教你30分钟快速搭建直播间
torch.roll
系统集成项目管理工程师认证高频考点:编制项目范围管理计划
What if the apple watch fails to power on? Apple watch can not boot solution!
「经验」爬虫在工作中的实战应用『实现篇』
深度学习编译器的理解
新版EasyGBS如何配置WebRTC视频流格式播放?
Deep learning compiler understanding
Troubleshooting MySQL for update deadlock
What if icloud photos cannot be uploaded or synchronized?
go之web框架 iris
AI首席架构师10-AICA-蓝翔 《飞桨框架设计与核心技术》