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);

待继续补充

  • 今天就写到这里啦~
  • 小伙伴们,( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ我们明天再见啦~~
  • 大家要天天开心哦

欢迎大家指出文章需要改正之处~
学无止境,合作共赢

在这里插入图片描述

欢迎路过的小哥哥小姐姐们提出更好的意见哇~~

posted @   糖~豆豆  阅读(85)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
Live2D
欢迎阅读『node.js系列-常见问题处理方案(持续更新)』
点击右上角即可分享
微信分享提示