node.js系列-常见问题处理方案(持续更新)
问题1:nodejs 如何使用 atob、btoa 解决方案(base64与uint8array转换),btoa和atob在nodejs中应该怎么写?
``
浏览器中我们可以这样使用:
btoa('123456')
'MTIzNDU2'
atob('MTIzNDU2')
'123456'
node.js中实现方案
const btoaText = Buffer.from("123456").toString("base64");
console.log(btoaText); // MTIzNDU2
const atobText = Buffer.from("MTIzNDU2", "base64").toString("binary");
console.log(atobText); // 123456
问题2:node.js中出现警告:ESLint - 'process' is not defined
解决方案:
修改eslint配置文件 , 举个栗子:.eslintrc.js
module.exports = {
"env": {
"node": true,
"es2021": true
},
"extends": "eslint:recommended",
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}
问题3:node.js中console.log如何变成彩色log
npm install colors
使用方案
import colors from "colors";
console.log(( "2023-08-02: " + _).bgGreen);
待继续补充
- 今天就写到这里啦~
- 小伙伴们,( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ我们明天再见啦~~
- 大家要天天开心哦
欢迎大家指出文章需要改正之处~
学无止境,合作共赢
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决