js常用小技巧
持续更新中……
判断对象是否为空Obeject.keys(obj) 返回不包括原型上的可枚举属性,即自身的可枚举属性
JSON.stringify(obj) 也是只能读取对象本身的可枚举属性
Object.getOwnPropertyNames(obj) symbol 作为 key 无法检测
for...in 会返回继承的属性
1Object.keys(obj).length === 0 && Object.getOwnPropertySymbols(obj).length === 0
一般来说 Object.keys(obj).length === 0 就够了
格式化JSON字符串node写文件时如果直接把JSON数据转为字符串,数据会全在一行比较丑,不方便阅读
1{"code":200,"message":"success","pagination":{"currentPage":1,"pageSize":2," ...
重温webpack
项目初始化安装webpack、webpack-cli
1npm i webpack webpack-cli -D
新建src/index.js文件,根目录新建webpack.config.js
1234567891011// webpack.config.jsconst path = require('path')module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'build.js' }}
loader的使用css处理postcss-loader,一般配合 Autoprefixer 使用,自动获取浏览器的流行度和能够支持的属性,并根据这些数据帮你自动为 CSS 规则添加前缀
12npm i style-loader css-loader postcss-loader -Dnpm i autop ...
Centos安装使用Nginx
下载安装下载地址:https://nginx.org/en/download.html
123456wget https://nginx.org/download/nginx-1.21.2.tar.gztar -zxvf https://nginx.org/download/nginx-1.21.2.tar.gzmv nginx-1.21.2 nginxcd nginx./configure --prefix=/opt/nginx # 配置安装路径,默认安装 /usr/local/nginx,可根据自己喜好make && make install # 如果系统是最小安装,需要执行 yum install make -y
开启nginx
123456789101112131415161718192021222324252627cd /opt/nginx/sbin./nginx[root@instance-1 sbin]# curl 34.125.204.106<!DOCTYPE html><html><head><title&g ...
frp内网穿透
frp下载地址:https://github.com/fatedier/frp/releases
frp官方文档:https://gofrp.org/docs
服务端frps配置下载123wget https://github.com/fatedier/frp/releases/download/v0.37.1/frp_0.37.1_linux_amd64.tar.gztar -zxvf frp_0.37.1_linux_amd64.tar.gzmv frp_0.37.1_linux_amd64 frp
配置阿里云服务器需要配置安全组,开放6000/8000端口
查看防火墙状态:systemctl status firewalld.service,如果出现绿色字样标注的“active(running)”,说明防火墙是开启状态,执行systemctl stop firewalld.service关闭防火墙
123456cd frpvim frps.ini[common]bind_port = 7000token = xxxx
挂载12345678910111213141516vi ...
Docker部署NodeJS项目
参考文档:https://nodejs.org/zh-cn/docs/guides/nodejs-docker-webapp
安装node镜像1docker pull node # 默认安装 node:latest 最新版
进入node项目
新建 Dockerfile 、.dockerignore文件
Dockerfile:
123456789101112FROM node:latestWORKDIR /usr/src/appCOPY package*.json ./RUN npm installCOPY . .EXPOSE 9000CMD [ "node", "app.js" ]
.dockerignore:
12node_modulesnpm-degub.log
目录结构
123456.|-- app.js|-- Dockerfile|-- .dockerignore|-- package.json`-- package-lock.json
构建镜像1docker build . -t <username>/node- ...
Docker学习
CentOS安装docker参考文档:
Docker CE 镜像源站-阿里云开发者社区
Install Docker Engine on CentOS
123yum install -y yum-utilsyum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoyum install docker-ce docker-ce-cli containerd.io
启动docker服务1systemctl start docker
将docker加入开机自启1systemctl enable docker
查看是否安装成功1docker version
配置阿里云镜像加速器
登录阿里云控制台
点击容器镜像服务
点击 镜像工具 -> 镜像加速器
选择适合自己的服务器版本
12345678sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF ...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick StartCreate a new post1$ hexo new "My New Post"
More info: Writing
Run server1$ hexo server
More info: Server
Generate static files1$ hexo generate
More info: Generating
Deploy to remote sites1$ hexo deploy
More info: Deployment