Node/包 管理

锁定Node版本 // package.json "engines":{ "node": "14.x || 16.xp" } // .npmrc engine-strict = true 锁定包 npm install -D only-allow only-allow npm、only-allow pnpm、only-allow yarn // package.json "scripts": { "preinstall": "only-allow npm", ... }

read more..

express 请求者IP

正常情况下: console.log(req.ip); // ::ffff:123.23.12.1 使用nginx代理后: location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:2012; p...

read more..

随机数random.org

https://www.random.org/integers/?num=500&min=0&max=12&col=1&base=10&format=plain&rnd=new 其中: num: 随机多少个 min:其中最小的数 max:其中最大的数

read more..

nodejs 反向代理 http-proxy-middleware

const express = require('express'); const app = express(); const proxy = require('http-proxy-middleware'); const port = 3000 const bodyParser = require('body-parser'); app.use(require('cors')()) app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()) var exampleProxy = proxy.createProxyMiddleware({ target: 'http://127.0.0.1:3001', chang...

read more..

Nodejs+Express 权限下载文件

先请求一个TOKEN(以用户生成,并且设置过期时间). 以token做验证去下载. 或者直接发送登录的token下载 const express = require('express'); const app = express(); const port = 51413; const bodyParser = require('body-parser'); app.use(require('cors')()) app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()) app.use(express.static('./public')) cons...

read more..

Nodejs+Express+Vue 分片上传文件

Vue <template> <div class="upload"> <el-upload :before-upload="befUpload" class="upload-demo" drag action="/" :show-file-list="false" > <el-icon class="el-icon--upload"><upload-filled /></el-icon> <div class="el-upload__text">拖拽或<em>点击上传</em></div> </el-upload> </div> <...

read more..

下载文件

function downloadFile(u) { http.get(u, (res) => { var data = ""; res.setEncoding('binary'); res.on('data', function (chunk) { data += chunk }) res.on('end', () => { let filename = Date.now(); fs.writeFileSync(`./ppx/${filename}.mp4`, data, 'binary') console.log(filename + 'end'); ...

read more..

Nodejs对接微信公众号(订阅号)

公众号配置 在开启服务器配置的时候需要验证自己的url. router.get('/api/send', (req, res) => { let token = wxToken; let signature = req.query.signature; let timestamp = req.query.timestamp; let nonce = req.query.nonce; let echostr = req.query.echostr; let arr = [token, timestamp, nonce]; arr = arr.sort(); let str = arr.join(''); ...

read more..

Server酱

NodeJs 封装一个简单的请求.key:server酱SCKEYtext:标题desp:内容(支持MarkDown) const https = require('https'); var iconv = require("iconv-lite"); function serverBot(key = '', text = '', desp = '') { return new Promise((resolve, reject) => { let url = `https://sc.ftqq.com/${key}.send?text=${text}&desp=${desp}` https.get(url, function (res) { ...

read more..

TgBot

先去@BotFather创建一个机器人,具体步骤谷歌,拿到TOKEN npm i node-telegram-bot-api const token = "XXXXXXX"; const TelegramBot = require('node-telegram-bot-api'); const bot = new TelegramBot(token, {polling: true}); //监听信息 bot.on('message', (msg) => { //处理函数 // msg.chat.id 相当于用户ID // bot.sendMessage(msg.chat.id,"发送的文本"); }); on...

read more..