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

待继续补充

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

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

在这里插入图片描述

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

猜你喜欢

转载自blog.csdn.net/tangdou369098655/article/details/132074661