specifying mongo port

This commit is contained in:
sairaj mote 2024-02-01 21:05:17 +05:30
parent 4789885f1c
commit 4551364596
2 changed files with 4 additions and 2 deletions

View File

@ -11,6 +11,8 @@ const app = express();
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || '127.0.0.1';
const MONGOPORT = process.env.MONGOPORT || 27017;
const MONGOHOST = process.env.MONGOHOST || '127.0.0.1'
// Middleware to parse JSON requests
app.use(express.json());
@ -30,7 +32,7 @@ app.use(
);
// connect to MongoDB
mongoose.connect(`mongodb://${HOST}/price-history`);
mongoose.connect(`mongodb://${MONGOHOST}:${MONGOPORT}/price-history`);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {

2
index.min.js vendored
View File

@ -1 +1 @@
require("dotenv").config();const express=require("express"),mongoose=require("mongoose"),cors=require("cors"),rateLimit=require("express-rate-limit"),path=require("path"),app=express(),PORT=process.env.PORT||3e3,HOST=process.env.HOST||"127.0.0.1";app.use(express.json()),app.use(cors()),app.use(rateLimit({windowMs:6e4,max:30})),mongoose.connect(`mongodb://${HOST}/price-history`);const db=mongoose.connection;db.on("error",console.error.bind(console,"connection error:")),db.once("open",(()=>{console.log("Connected to MongoDB")})),app.get("/",((req,res)=>{res.sendFile(path.join(__dirname,"./index.min.html"))}));const hash=require("./routes/hash");app.use("/hash",hash);const priceHistory=require("./routes/price-history");app.use("/price-history",priceHistory),app.listen(PORT,HOST,(()=>{console.log(`Server is running at http://${HOST}:${PORT}`)})),module.exports=app;
require("dotenv").config();const express=require("express"),mongoose=require("mongoose"),cors=require("cors"),rateLimit=require("express-rate-limit"),path=require("path"),app=express(),PORT=process.env.PORT||3e3,HOST=process.env.HOST||"127.0.0.1",MONGOPORT=process.env.MONGOPORT||27017,MONGOHOST=process.env.MONGOHOST||"127.0.0.1";app.use(express.json()),app.use(cors()),app.use(rateLimit({windowMs:6e4,max:30})),mongoose.connect(`mongodb://${MONGOHOST}:${MONGOPORT}/price-history`);const db=mongoose.connection;db.on("error",console.error.bind(console,"connection error:")),db.once("open",(()=>{console.log("Connected to MongoDB")})),app.get("/",((req,res)=>{res.sendFile(path.join(__dirname,"./index.min.html"))}));const hash=require("./routes/hash");app.use("/hash",hash);const priceHistory=require("./routes/price-history");app.use("/price-history",priceHistory),app.listen(PORT,HOST,(()=>{console.log(`Server is running at http://${HOST}:${PORT}`)})),module.exports=app;