'I try to dockerizing my node server but I got an Error: Cannot find module './router/Seller'
Here is my server.js file. I try to dockerizing my node server but I got an Error: Cannot find module './router/Seller'. How can I solve this problem?
const express = require("express");
const cors = require("cors")
const app = express();
const mongoose = require("mongoose");
const dotenv = require("dotenv")
const port = 5000;
const SellerRouter = require('./router/Seller');
dotenv.config();
mongoose.connect(`mongodb+srv://name:[email protected]/Databasename?retryWrites=true&w=majority`).then(()=>console.log("DB connected successfully")).catch((error)=>{
console.log(error)
})
app.use(cors());
app.use(express.json());
app.use("/api/seller" , SellerRouter)
app.listen(port, ()=>{
console.log(`SERVER IS RUNNING at http://localhost:${port}`)
})
Here is my Dockerfile:
FROM node:16
WORKDIR /Backend
ENV PATH="./node_modules/.bin:$PATH"
COPY . .
COPY package*.json ./
RUN npm install
CMD [ "node", "index.js" ]
ENV MONGO_URL = mongodb+srv://name:Your [email protected]/Databasename?retryWrites=true&w=majority
ENV JWT_SEC = Your password
ENV PASS_SEC = Yourr password
Here is my result which means error
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Backend/index.js:9:22)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Backend/index.js' ]
}
PS C:\Users\khadk\OneDrive\Desktop\dd>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
