NVM

How do I install NVM

  • Brew download address:

1, brew. Sh /

2, gitee.com/cunkai/Home…

  • NVM: NodeJS version management tool, which can switch between multiple NodeJS versions.

  • MacOS: Brew install NVM;

  • Windows: GitHub search nVM-Windows, there is a download address.

Manage NodeJS using NVM

  • NVM list Displays all current node versions.

  • NVM install v12.19.0 Install the specified version.

  • NVM use –delete-prefix 12.19.0 Switch to the specified version;

  • NVM Alias Default v12.19.0 Set the default version.

MYSQL

Install mysql on Ubuntu

Blog.csdn.net/weixin\_422…

Download MySQL

Dev.mysql.com/downloads/m…

Download the workbench

Dev.mysql.com/downloads/w…

use

Common data types for table construction: int, BIGINT, VARCHAR, longtext

-- show databases; -- Use Leslie database -- Use Leslie; Insert into users(username, 'password ', realname) values('zhangsan', '123456', 'zhangsan') Select * from users; select * from users; Select username, 'password' from users; Select * from users where username = 'zhangsan' and realname = 'zhangsan'; select * from users where username = 'zhangsan'; Select * from users where username like '%zhang%' and 'password' like '%1%'; Select * from users where 'password' like '%1%' ORDER by id desc; Update users set realName = 'lisi' where username = 'lisi'; Delete from users where username = 'lisi'; Update users set state = '0' where username = 'lisi'; -- select * from users where state <> '0'Copy the code

MONGODB

Install mongodb in Ubuntu

– mongodb install on ubuntu docs

Docs.mongodb.com/manual/tuto…

Install mongodb on a MAC

– mongodb install on mac docs

Github.com/mongodb/hom…

use

-- Show all databases -- show DBS -- Create/use a database -- use Leslie -- Show collections -- create/use users document -- db.users. 'username': 'zhangsan', 'password': '123456', 'realname': Find (db.users.find() -- db.users.find({'username': 'username') -- db.users.find({'username': 'zhangsan'}) -- db.users.find({age: = 22}) -- db.users.find({age: = 22}) 22}), query the users documents under age 22 record - > db. Users. Find ({age: {$gt: 22}}) - age < query users post on the records of 22 - db. Users. Find ({age: {$lt: 22}}), query the users documents under age > = 22 record -- db. Users. Find ({age: {$gte: 22}}), query the users documents under age < = 22 record - db. Users. Find ({age: {$lte: 22}}), query the users documents under age > = 20 && age < = 23 records - db. Users. Find ({age: {$gte: 20, $lte: 23}}), query the users under the document name contained in the mongo data -- the db. Users. Find ({name: /mongo/}) -- db.users.find({name: /mongo/}) -- db.users.find({name: /mongo/}) /^mongo/}) -- db.users.find({}, {name: 1, age: 1) -- db.users. 1}) -- query users documents under the specified column name, the age, the age > 20 -- db. Users. Find ({age: {$gt: 20}, {name: 1, the age: True}}) -- db.users.find().sort({age: 1}) -- db.users.find().sort({age: -- db.users.find(). Limit (10) -- db.users.find(). Skip (5) -- db.users.find( Db.users.find ().limit(10).skip(5) -- query the first data in users document -- db.users.findone () -- query the number of records in a result set in Users document -- Db.users. find(age: {$gt: 20}).count() -- change the age of all users named "zhangsan" in users file to 16 -- db.users.update({username: 'zhangsan'}, {$set: {age: 16}}, {multi: true}) -- db.users.remove({age: 16}) -- $set: {age: 16}, {multi: true}) 16 }, { justOne: true })Copy the code

PM2

Download and install

  • npm i pm2 -g
  • pm2 –version

Common commands

  • pm2 start … , pm2 list
  • pm2 restart /
  • Pm2 stop /, pm2 delete /
  • pm2 info /
  • pm2 log /
  • pm2 monit /

The process to protect

  • Nodeapp. js and Nodemon App. js cannot be accessed if the process crashes

  • If the PM2 process crashes, it automatically restarts

Node.js interview questions

What is NodeJS?

  • Nodejs is a JavaScript runtime based on the Chrome V8 engine.

  • Before NodeJS, js could only be run in a browser;

  • Once nodeJS is available, js can run in any environment where NodeJS is installed.

Difference between NodeJS and front-end JS

grammar

  • Both use ES syntax;
  • Front-end JS uses THE JS Web API;
  • Nodejs uses the Node API.

application

  • Front-end JS for web pages, running in the browser;

  • Nodejs can be used on the server side, such as developing a Web server;

  • Nodejs can also be used with native tools such as Webpack.

How to debug NodeJS

  • To start the nodejs service, use inspect;

  • Use debugger breakpoints in code

  • Debug using Chrome – Chrome ://inspect.

How to obtain the path of the current file and directory?

  • __filename;

  • __dirname;

  • Both are global variables.

Commonjs and ES6 Modules

  • Grammar is different
  • Commonjs is dynamically imported at execution time;
  • ES6 Modules are statically imported and are imported at compile time.

Path. reslove differs from path.join

  • Both are used to concatenate paths;
  • Path. reslove gets the absolute path;
  • Path. join Obtains the relative path.

The difference between Event loop in browser and NodeJS

  • Nodejs has more asynchronous apis and more macro task types.

  • Nodejs Event loop is divided into 6 stages, which should be executed in sequence.

  • Process. nextTick has a higher priority in microtasks.

Async /await execution order problem

How to log in session?

  • Cookie how to achieve login verification;
  • The relationship between session and cookie;
  • Why sessions need to be stored in Redis.

Describes the middleware mechanisms of KOA2 and Express

  • In code, middleware is a function;

  • From the business point of view, middleware is an independent module;

  • Some fast separation, module flow, can complete complex functions.

Read a large file – stream

  • One gigabyte of access.log;

  • Analyze the proportion of Chrome browser.

  • Consider CPU and memory limits.

Why is multi-process enabled on nodeJS?

  • Efficient use of multi-core CPU;
  • Make full use of server memory;
  • Final: Squeeze the server without wasting resources.