Gahing's blog Gahing's blog
首页
知识体系
  • 前端基础
  • 应用框架
  • 工程能力
  • 应用基础
  • 专业领域
  • 业务场景
  • 前端晋升 (opens new window)
  • Git
  • 网络基础
  • 算法
  • 数据结构
  • 编程范式
  • 编解码
  • Linux
  • AIGC
  • 其他领域

    • 客户端
    • 服务端
    • 产品设计
软素质
  • 面试经验
  • 人生总结
  • 个人简历
  • 知识卡片
  • 灵感记录
  • 实用技巧
  • 知识科普
  • 友情链接
  • 美食推荐 (opens new window)
  • 收藏夹

    • 优质前端信息源 (opens new window)
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Gahing / francecil

To be best
首页
知识体系
  • 前端基础
  • 应用框架
  • 工程能力
  • 应用基础
  • 专业领域
  • 业务场景
  • 前端晋升 (opens new window)
  • Git
  • 网络基础
  • 算法
  • 数据结构
  • 编程范式
  • 编解码
  • Linux
  • AIGC
  • 其他领域

    • 客户端
    • 服务端
    • 产品设计
软素质
  • 面试经验
  • 人生总结
  • 个人简历
  • 知识卡片
  • 灵感记录
  • 实用技巧
  • 知识科普
  • 友情链接
  • 美食推荐 (opens new window)
  • 收藏夹

    • 优质前端信息源 (opens new window)
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 前端基础

  • 应用框架

  • 工程能力

  • 应用基础

  • 专业领域

    • 服务端

      • Deno

      • Node.js

        • Node.js 版本切换
        • Node子进程执行ping操作并获取统计信息
        • Node 中的当前目录路径
        • node小bug记录
          • 1.使用exec命名,中文输出乱码
          • 2. sql批量插入
          • 3. 下载文件,文件名乱码
        • 事件驱动理解
        • 小技巧:Chrome 在线调试 Node
        • 深入浅出Node.js
        • log4js配置详解
        • node 模块源码解析

        • nodejs文件下载
      • 服务端框架

    • 跨端技术

    • Web IDE

    • 中后台

    • 动效渲染

    • 可视化

    • 埋点监控

    • 多媒体

    • 桌面技术

    • 游戏互动

    • 编辑器

    • 虚拟化与容器化

    • 设计系统

  • 业务场景

  • 大前端
  • 专业领域
  • 服务端
  • Node.js
gahing
2020-03-22
目录

node小bug记录草稿

# 1.使用exec命名,中文输出乱码

使用 iconv-lite

demo:

var exec = require('child_process').exec;
var iconv = require('iconv-lite');
exec('ping 127.0.0.1',{encoding:'binary'},function(err,stdout,stderr){
    let str = iconv.decode(new Buffer(stdout,'binary'),'GBK')
    console.log(str)
});
1
2
3
4
5
6

# 2. sql批量插入

this.connection.query('INSERT INTO user(id,name) VALUES ?',[[[1,'a'],[2,'b']]])
1

注意的是params参数外面包了一层[],sql语句 VALUES后面只带?

# 3. 下载文件,文件名乱码

try {
    var filePath = path.join(__dirname, '../') + '/files/xls/demo.xlsx'
    // 定位到具体文件
    var stats = fs.statSync(filePath)
    if (stats.isFile()) {
      // 对指定的中文名进行utf8编码,否则直接filename=中文名 将不生效还是使用原来文件名
      res.set({
        'Content-Type': 'application/octet-stream',
        'Content-Disposition': "attachment; filename*=UTF-8''" + encodeURI('App提交模板.xlsx'),
        'Content-Length': stats.size
      })
      res.send(stats)
    } else {
      res.status(404).end()
    }
  } catch (error) {
    res.status(404).end()
  }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
编辑 (opens new window)
上次更新: 2024/09/01, 23:56:56
Node 中的当前目录路径
事件驱动理解

← Node 中的当前目录路径 事件驱动理解→

最近更新
01
浅谈代码质量与量化指标
08-27
02
快速理解 JS 装饰器
08-26
03
Vue 项目中的 data-v-xxx 是怎么生成的
09-19
更多文章>
Theme by Vdoing | Copyright © 2016-2024 Gahing | 闽ICP备19024221号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式