WishMeLz

生活其实很有趣

分类 NodeJS 下的文章

SSE(Server-Sent Events)

服务端const express = require("express"); const cors = require("cors"); const app = express(); const port = 6548; app.use(cors()); app.get("/sse", (req, res) => { res.set({ "Content-Type": "text/event-stream", &quo...

EA Racenet API

公共请求头:const headers = { Authorization: `Bearer eyJraWQiOiIw` }1、查询GET:https://web-api.racenet.com/api/Friend/profile 好友中搜索GET:https://web-api.racenet.com/api/Friend/search 非好友中搜索请求参数,路径参数{ searchTerm: "", // 搜索关键字 pageNumber: 1, pageSize: 20, in...

Minio 之 Nodejs

docker run -p 9000:9000 -p 9090:9090 --net=host --name minio -d --restart=always -e "MINIO_SERVER_URL=http://111.73.12.186:9000" -e "MINIO_ACCESS_KEY=asd123" -e "MINIO_SECRET_KEY=ert123" -v /home/minio/data:/data -v /home/minio/config:/root/.minio...

nuxt项目本地启动,多开标签一直显示加载中

本地npm run dev启动,多开几个标签页,会出现卡死或一直转圈的情况,如果关闭其中一个tab标签,卡死的tab标签页就会立即加载完成,控制台看不到任何错误信息。 因为浏览器对同一个主机有连接数限制。官方解释:https://github.com/nuxt/nuxt/issues/8190

nvm win10安装

先卸载nodehttps://github.com/coreybutler/nvm-windowshttps://github.com/coreybutler/nvm-windows/releases安装最新版本的 Node: nvm install latest安装 LTS 版本的 Node: nvm install lts安装指定版本: nvm install 14.11.12安装大版本:nvm install 14查看版本:nvm list使用版本:nvm use 14

非对称加密(node-rsa,jsencrypt)

公钥私钥生成随便找个在线生成的http://www.metools.info/code/c80.htmlORconst NodeRSA = require('node-rsa') const fs = require('fs') const newkey = new NodeRSA({ b: 512 }) newkey.setOptions({ encryptionScheme: 'pkcs1' }) let public_key = newkey.exportKey('pkcs8-public') //公钥 let private_key =...

request获取重定向的地址

var r = request(url, function (e, response,body) { r.uri response.request.uri console.log(response.statusCode); console.log(this.uri.href); })

Node/包 管理

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

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...

随机数random.org

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

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(...

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(bodyP...

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 cla...

下载文件

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.wr...

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, timesta...

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?t...

TgBot

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

NodeJs抓取页面

npm i cheerio request iconv-lite思路:通过 request 获取到页面。在使用 iconv-lite 编译数据。在使用 cheerio 拿到对应的元素。这里以抓取微博热搜为例const cheerio = require('cheerio'); const request = require('request'); const iconv = require('iconv-lite'); function http(url, decode = 'utf8') { return new Promise((res...

MySql3306端口笔记Can’t connect to MySQL server(60)的问题

阿里云服务器。端口全开。防火墙关闭。安全组端口全开。就是连不上。Can’t connect to MySQL server(60)的问题 sudo iptables -L可以看到一条mysql的规则。这个时候需要把他删掉sudo iptables -L -n --line-number sudo iptables -D INPUT 6

NodeJs抓取页面内容

const cheerio = require('cheerio'); const request = require('request'); let url = 'https://btc.com/' request({ url: url, encoding: null }, function (error, response, body) { if (!error && response.statusCode == 200) { var buf = iconv.decode(body...