Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Not getting MongoDB data When i host my app in my IP address

I am not a very good programmer but i make an app with nodejs and express when i was making the app i use this line of code to host the server on localhost:8000 the line of code is :

var server = http.listen(8000,() => {
  console.log("server is listening on port", server.address().port);
});

when i was using this line of code like that all was good.

When my app is done i changed the like of code to:

var server = http.listen(8000, "192.168.0.111", () => {
  console.log("server is listening on port", server.address().port);
});

then only the html and css is working but not the server.js file, the server.js file is:

var express = require("express");
var bodyParser = require("body-parser");
var app = express();
var http = require("http").Server(app);
var io = require("socket.io")(http);
var mongoose = require("mongoose");
const { sendStatus } = require("express/lib/response");

app.use(express.static(__dirname));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));

var dbUrl = "mongodb+srv://<username>:<password>@learning-node.14s4f.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"

var Message = mongoose.model("Message", {
  name: String,
  message: String
});

app.get("/messages", (req, res) => {
  Message.find({}, (err, messages) => {
    res.send(messages);
  });
});

app.post("/messages", (req, res) => {
  var message = new Message(req.body);

  message.save((err) => {
    if (err) {
      sendStatus(500);
    }

    Message.findOne({message: "badword"}, (err, censored) => {
      if (censored) {
        console.log("Censored word Found", censored);
        Message.remove({_id: censored.id }, (err) => {
          console.log("Removed censored Message");
        })
      }
    });

    io.emit("message", req.body);
    res.sendStatus(200);
  });
});

io.on("connection", (socket) => {
  console.log("A new user Connected !");
});

mongoose.connect(dbUrl, (err) => {
  console.log("MongoDB Connection", err);
});

var server = http.listen(8000, "192.168.0.111", () => {
  console.log("server is listening on port", server.address().port);
});

and the mongoDB data is not being imported Please Help ME !!! T-T

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!