1. 技术栈
后端采用nodejs + koa web框架进行开发
2. 开发接口统计
2.1 获取图片的宽高
npm install image-size
const axios = require("axios");
const sizeOf = require("image-size");
const imageInfo = function(imageUrl){
return new Promise(async (resolve, reject) => {
try {
const res = await axios.get(imageUrl, {responseType: "arraybuffer"});
console.log("imageInfo res:", res);
const buffer = Buffer.from(res.data, "binary");
const size = sizeOf(buffer);
console.log(size);
resolve({
width: size.width,
height: size.height
});
} catch (error) {
console.log(error);
reject(error);
}
})
}
module.exports = imageInfo;
console.log(size)的日志 { height: 1000, width: 562, type: 'jpg' }
3. 常见命令
node -v
npm -v
npm init 一路回车就可以
npm install koa
npm install koa-json
npm install koa-bodyparser
npm install @koa/router @koa/cors mongoose
npm install nodemon -g
启动命令: nodemon app.js
4. 学习进度
看到第83了