The flowing code successfully connects mongoose with the mlab database on localhost and Heroku. But it's not working on Namecheap node js Server.
const express = require("express");
const mongoose = require("mongoose");
const port = parseInt(process.env.PORT, 10) || 3000;
const server = express();
mongoose.connect("mongodb://@ds213645.mlab.com:13645/techblog", {
useNewUrlParser: true,
auth: {
user: "user",
password: "pass"
}
});
const Schema = mongoose.Schema;
const userSchema = new Schema(
{
name: String,
email: String
},
{ timestamps: true }
);
const User = mongoose.model("User", userSchema);
server.get("/test", async (req, res) => {
const user = new User({ name: "SomeName", email: "your@email.com" });
const userData = await user.save();
res.send(userData);
});
server.get("/", async (req, res) => {
res.send("working");
});
server.listen(port, err => {
if (err) throw err;
console.log(`> Ready on ${port}`);
});
When I hit the root('/') route it works perfectly on Namecheap server but when I hit test('test') route it response 'Incomplete response received from application' after a long time. So what is the way to connect mongoose with the database on Namecheap shared hosting?