Emojis are not rendering in the terminal when using the logger.info() , logger.warn, etc

200 Views Asked by At

When using the console.log() the emojis are rendered in the terminal but when using logger.info() , logger.warn() , etc emojis didn't appropriately render. I used Pino-pretty.

src/app.js utils/logger.js

import express from "express";

import cors from "cors";
import logger from "./utils/logger";
import "dotenv/config";

const app = express();
const PORT = process.env.PORT || "8090";

app.use(cors());
app.use(express.json({ 
    limit: "20mb" 
}));

app.get("/", (req, res, next) => {
res.send("<h2> Library Management System API</h2>");
next();
});

app.listen(PORT, () => {
    console.log(`Listening on PORT ${PORT}`);
    logger.info(`Listening on PORT ${PORT} `);

    logger.info("This is testing");
    logger.error("This is error");
    logger.warn("This is warning");
});

--Output in the terminal--

[nodemon] restarting due to changes...

[nodemon] starting babel-node src/app.js

Listening on PORT 8090

[24-02-2023 14:37:41] INFO: **🚀**Listening on PORT 8090

[24-02-2023 14:37:41] INFO: This is testing

[24-02-2023 14:37:41] ERROR: This is error

[24-02-2023 14:37:41] WARN: This is warning

I expected the relevant emoji but it showed like 🚀

1

There are 1 best solutions below

0
Hasitha On

You have to add "chcp 65001" to your script tag in package.json.

"scripts": { "start": "chcp 65001 && nodemon --exec file-path" }