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

待继续补充

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

欢迎大家指出文章需要改正之处~

学无止境,合作共赢

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

相关推荐
垣宇12 小时前
Vite 和 Webpack 的区别和选择
前端·webpack·node.js
爱吃南瓜的北瓜12 小时前
npm install 卡在“sill idealTree buildDeps“
前端·npm·node.js
翻滚吧键盘12 小时前
npm使用了代理,但是代理软件已经关闭导致创建失败
前端·npm·node.js
浪九天13 小时前
node.js的版本管理
node.js
浪九天15 小时前
node.js的常用指令
node.js
浪九天17 小时前
Vue 不同大版本与 Node.js 版本匹配的详细参数
前端·vue.js·node.js
小纯洁w1 天前
Webpack 的 require.context 和 Vite 的 import.meta.glob 的详细介绍和使用
前端·webpack·node.js
熬夜不洗澡1 天前
Node.js中不支持require和import两种导入模块的混用
node.js
bubusa~>_<1 天前
解决npm install 出现error,比如:ERR_SSL_CIPHER_OPERATION_FAILED
前端·npm·node.js
天下皆白_唯我独黑1 天前
npm 安装扩展遇到证书失效解决方案
前端·npm·node.js