'While deploy the MERN Stack at DigitalOcean error TextEncoder is not defined
My app works on development but gives Text Encoder error in production. When I run the Node index.js command, I get the error "TextEncoder is not defined".
Error
Index.js file
const dotenv = require("dotenv");
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const path = require("path");
const posts = require("./routes/posts.js");
const categories = require("./routes/categories.js");
const http = require("http");
dotenv.config();
const server = express();
const PORT = process.env.PORT || 5000;
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
server.use(cors());
mongoose
.connect(process.env.DATABASE_URI)
.then(() => console.log("connected mongodb"))
.catch(() => console.log("connection error"));
server.use("/api/posts", posts);
server.use("/api/categories", categories);
const httpServer = http.createServer(server);
if (process.env.NODE_ENV === "production") {
server.use(express.static(path.join(__dirname, "/client/build")));
server.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "/client" + "/build" + "/index.html"));
});
httpServer.listen(80);
} else {
server.listen(PORT, () => console.log("server listening at", PORT));
}
Package.json
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|