WishMeLz

生活其实很有趣

分类 NodeJS 下的文章

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

赛邮云通信SUBMAIL

NodeJs发送短信var request = require('request'); let post = function (url, postdata) { let options = { url: url, formData: postdata }; return new Promise(function (resolve, reject) { request.post(options, function (err, response, body) { ...

puppeteer脚本使用 浏览器

const puppeteer = require('puppeteer'); const browser = puppeteer.launch( { headless: true // true关闭ui,false打开ui } ); const page = browser.newPage(); // 实例化Apipage.goto(url) // 进入一个网站 page.click('#btn') // 点击某个元素 const input_areaUser = pa...

图形验证码

const svgCaptcha = require('svg-captcha'); var codeConfig = { size: 5,// 验证码长度 ignoreChars: '0o1i', // 验证码字符中排除 0o1i noise: 2, // 干扰线条的数量 height: 44 } var captcha = svgCaptcha.create(codeConfig); let code = captcha.text.toLowerC...

Node接口笔记

JTW 生成TOKEN let token = jsonwebtoken.sign({ id: data[0].id // 数据 }, secret, { expiresIn: 60 * 60 * 24 * 30 * 6 }) // 半年,过期时间 ,单位秒 secret为秘钥 解析 try { // 解析令牌,返回对象:{ exp: 过期时间, crt:创建时间 ...} userInfo = jwt.ve...