当前位置:网站首页>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
边栏推荐
- 法国A+ 法国VOC标签最高环保级别
- slice
- How to use AI technology to optimize the independent station customer service system? Listen to the experts!
- 《Go题库·15》go struct 能不能比较?
- 屏幕显示技术进化史
- Multipass Chinese document - setting graphical interface
- How to seamlessly transition from traditional microservice framework to service grid ASM
- Swin-Transformer(2021-08)
- Tensorflow2 ten must know for deep learning
- ForkJoinPool
猜你喜欢

PC端微信多开

Dlib library for face key point detection (openCV Implementation)

Teach you to quickly set up a live studio in 30 minutes

系统集成项目管理工程师认证高频考点:编制项目范围管理计划

20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘

Huaxing Securities: kitex practice under the original hybrid Cloud Architecture

MRO工业品采购管理系统:赋能MRO企业采购各节点,构建数字化采购新体系

德国AgBB VoC有害物质测试

mysql for update 死锁问题排查

Troubleshooting MySQL for update deadlock
随机推荐
countdownlatch 和 completableFuture 和 CyclicBarrier
TCP packet sticking problem
torch. roll
3.10 haas506 2.0 development tutorial example TFT
Infineon - GTM architecture -generic timer module
NEON优化2:ARM优化高频指令总结
Glacier teacher's book
What if icloud photos cannot be uploaded or synchronized?
《客从何处来》
Troubleshooting MySQL for update deadlock
[community star selection] the 23rd issue of the July revision plan | bit by bit creation, converging into a tower! Huawei freebuses 4E and other cool gifts
rust配置国内源
新版EasyGBS如何配置WebRTC视频流格式播放?
Coding officially entered Tencent conference application market!
torch.roll
mysql 递归
Solution of enterprise supply chain system in medical industry: realize collaborative visualization of medical digital intelligent supply chain
Detailed single case mode
【TiDB】TiCDC canal_ Practical application of JSON
MySQL transaction concurrency and mvcc mechanism