a = 1;
b = 2;
// method 1
[a, b] = [b, a]
// method 2
// b = [a, (a = b)][0];
// method 3
// or use destructuring
// [b] = [a, (a = b)];
console.log(a, b);
需要先安装 nodejs。
npm install pm2@latest -g
pm2 -h //查看帮助文档
pm2 list //列出当前 pm2 管理的所有进程
http://pm2.keymetrics.io/docs/usage/application-declaration/
# Start all applications
pm2 start ecosystem.config.js
# Start only the app named worker-app
pm2 start ecosystem.config.js --only worker-app
pm2 start ecosystem.config.js --env production
# Stop all
pm2 stop ecosystem.config.js
# Restart all
pm2 start ecosystem.config.js
## Or
pm2 restart ecosystem.config.js
# Reload all
pm2 reload ecosystem.config.js
# Delete all
pm2 delete ecosystem.config.js
pm2 ecosystem
生成配置文件 ecosystem.config.js
module.exports = {
apps: [
{
// name (string) application name.
name: 'filterServer',
// script (string) script path relative to pm2 start.
script: './filterServer.js',
// cwd (string) the directory from which you app will be launched.
cwd: './',
// args (string) all arguments passed to script.
// args: 'one two',
// interpreter (string) interpreter absolute path (default to node)
interpreter: 'node',
// interpreter_args (string) option to pass to the interpreter.
// interpreter_args: '-harmony',
// instances (number) number of app instance to be launched.
instances: 1,
// true by default. if false, PM2 will not restart your app if it
// crashes or ends peacefully
autorestart: true,
// a cron pattern to restart your app. Application must be running for
// cron feature to work
// cron_restart: '1 0 * * *',
// watch (boolean) enable watch & restart feature, if a file change in the
// folder or subfolder, your app will get reloaded.
watch: false,
// list of regex to ignore some file or folder names by the watch feature
ignore_watch: ['[/\\]./', 'node_modules'],
// your app will be restarted if it exceeds the amount of memory specified.
// human-friendly format : it can be “10M”, “100K”, “2G” and so on…
max_memory_restart: '1G',
// exec_mode (string) mode to start your app, can be "cluster" or "fork".
// default is "fork".
exec_mode: 'fork',
// (string) error file path (default to $HOME/.pm2/logs/XXXerr.log)
// error_file: '',
// output file path (default to $HOME/.pm2/logs/XXXout.log)
out_file: '/dev/null',
// pid file path (default to $HOME/.pm2/pid/app-pm_id.pid)
// pid_file: '',
env: {
NODE_ENV: 'development',
},
env_production: {
NODE_ENV: 'production',
},
},
],
};
if ({}) {
console.log('{} is true');
} else {
console.log('{} is false');
}
if (true) {
console.log('true is true');
} else {
console.log('true is false');
}
if (false) {
console.log('false is true');
} else {
console.log('false is false');
}
if (null) {
console.log('null is true');
} else {
console.log('null is false');
}
if (undefined) {
console.log('undefined is true');
} else {
console.log('undefined is false');
}
if (NaN) {
console.log('NaN is true');
} else {
console.log('NaN is false');
}
if ('') {
console.log('empty string(\'\') is true');
} else {
console.log('empty string(\'\') is false');
}
if (0) {
console.log('0 is true');
} else {
console.log('0 is false');
}
if (-0) {
console.log('-0 is true');
} else {
console.log('-0 is false');
}
if (1) {
console.log('1 is true');
} else {
console.log('1 is false');
}
if (-1) {
console.log('-1 is true');
} else {
console.log('-1 is false');
}
if ('true') {
console.log('\'true\' is true');
} else {
console.log('\'true\' is false');
}
if ('false') {
console.log('\'false\' is true');
} else {
console.log('\'false\' is false');
}
if ('0') {
console.log('\'0\' is true');
} else {
console.log('\'0\' is false');
}
if ('1') {
console.log('\'1\' is true');
} else {
console.log('\'1\' is false');
}
输出:
{} is true
true is true
false is false
null is false
undefined is false
NaN is false
empty string('') is false
0 is false
-0 is false
1 is true
-1 is true
'true' is true
'false' is true
'0' is true
'1' is true
mysql --help
mysql -h 127.0.0.1 -u root -P 3306 -p
-h: 指定 IP 地址
-u: 指定用户
-P: 指定端口(这个是大写的 P)
-p: 指定要输入密码,这个后面不需要跟参数
show databases;
use <数据库名>;
mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
show tables;
mysql> select database();
+--------------------+
| database() |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.7.27-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0.01 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2019-09-27 10:19:47 |
+---------------------+
1 row in set (0.00 sec)
mysql> select CURRENT_DATE;
+--------------+
| CURRENT_DATE |
+--------------+
| 2019-09-27 |
+--------------+
1 row in set (0.00 sec)
mysql> select YEAR(CURRENT_DATE);
+--------------------+
| YEAR(CURRENT_DATE) |
+--------------------+
| 2019 |
+--------------------+
1 row in set (0.00 sec)
mysql> select MONTH(CURRENT_DATE);
+---------------------+
| MONTH(CURRENT_DATE) |
+---------------------+
| 9 |
+---------------------+
1 row in set (0.00 sec)
mysql> select DAYOFMONTH(CURRENT_DATE);
+--------------------------+
| DAYOFMONTH(CURRENT_DATE) |
+--------------------------+
| 27 |
+--------------------------+
1 row in set (0.00 sec)
nvm 不是一个命令行工具,nvm 是一个 shell 函数。
所以需要用 command -v nvm
来查看是否安装成功了。
nvm -h
$ nvm ls
v8.16.0
v10.16.3
-> v12.11.0
system
default -> 12.11.0 (-> v12.11.0)
node -> stable (-> v12.11.0) (default)
stable -> 12.11 (-> v12.11.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/dubnium (-> v10.16.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.1 (-> N/A)
lts/dubnium -> v10.16.3
Example:
nvm install 8.0.0 Install a specific version number
nvm use 8.0 Use the latest available 8.0.x release
nvm run 6.10.3 app.js Run app.js using node 6.10.3
nvm exec 4.8.3 node app.js Run `node app.js` with the PATH
pointing to node 4.8.3
nvm alias default 8.1.0 Set default node version on a
shell
nvm alias default node Always default to the latest
available node version on a shell
nvm alias default system
nvm use 10.16.3
npm install
根据 package.json
文件中的 dependencies
和
devDependencies
来安装模块。
npm install --production
根据 package.json
文件中的 dependencies
来安装
模块。
并写入 package.json 文件的 dependencies
里面。
npm install moduleName
具体安装到哪里,可以用 npm config get prefix
查看。
npm install -g moduleName
并写入 package.json 文件的 dependencies
里面。
npm install --save-prod moduleName
并写入 package.json 文件的 devDependencies
里面。
npm install --save-dev moduleName
一些开发时会用到的,但是部署时用不到的,就用 -save-dev
,比如 eslint
。
新建项目的时候,使用这个命令会在当前目录下创建 package.json
文件。
npm init