0

I developed a Node.js RestAPI to communicate with a MongoDB database. While I was developing using localhost everything worked fine, but now I need to deploy it to a server so users can test it.

The server is running Ubuntu 16.04, and I have successfully installed the software I need (Node.js and MongoDB) and I'm able to start the server, however, I can't make any request using the client.

If I ping the server I'm able to get a response. I have my Node.js RestAPI running on port 4000.

Any idea what I might be doing wrong or what I might have forgotten? This is the first time I'm deploying to a server.

My server.js file is:

const port = 4000

const bodyParser = require('body-parser')
const express = require('express')

const jwt = require('jsonwebtoken')
const cors = require("cors")
const mongoose = require('mongoose')
const databaseConfig = require('./database')

const server = express()

server.use(cors())
server.options('*', cors());

server.use(bodyParser.urlencoded({ extended: true }))
server.use(bodyParser.json())

server.set('superSecret', databaseConfig.secret)

server.listen(process.env.port || port, function () {
    console.log('Listening')
})

mongoose.connect(databaseConfig.database, function(err, db) {
    if (err) {
        console.log('Unable to connect to the server. Please start the server. Error:', err);
    } else {
        console.log('Connected to Server successfully!');
    }
});

module.exports = server

Any help is appreciated. Thank you.

kyrers
  • 489
  • 1
  • 6
  • 22

1 Answers1

0

To stop anyone from wasting time on this topic turns out the employee at my university that was supposed to make the host machine IP public forgot to do it! That was the problem, nothing else.

kyrers
  • 489
  • 1
  • 6
  • 22