I feel quite silly trying to describe this issue but- i'm trying to build more full stack projects and in the process built a great little app that took votes, store the results of all the votes in a database (using SSMS), and the displayed the results. Works perfectly- locally.
I'm trying to now add this project to my website so prospective employers can use it/see it. My website is hosted on hostmonster so I made an SQL server there and change the appropriate configurations.
Well, it doesn't work and i'm 99% the reason is because of my express server. I have this server.js file:
const express = require('express')
const databaseOperations = require('./src/database/operations')
const cors = require('cors')
const API_PORT = process.env.PORT || 4000;
const app = express()
app.use(express.json())
app.use(express.urlencoded({extended: true}));
app.use(cors())
app.get('/api', async (req, res) => {
const result = await databaseOperations.getGraphVotes();
res.send(result)
});
app.listen(API_PORT, () => console.log(`listening on port ${API_PORT}`))
Then in my component files i've got variables like this:
const newData = await fetch('https://example.com:4000/api', {
(example.com being my domain of course)
My question is, do I need to set up that port somehow through hostmonster? I don't see any documentation or anything on how to do that. And I feel like I don't quite know enough to know what to search to figure this out. How do I set up this express server?
Again, it worked great when it was on my local machine but I can't figure out how this works through a service like hostmonster.
Thanks.
There could be some possible reasons why you can't access the Node express server.
Your server does not start when you run the application - it could be due to an incorrect entry point given in the host monster configuration.
It does start and you should check the logs to validate it - it is not accessible from the outside.
Solution:
You should check the logs and validate if your node server is serving the request - this message would be enough: listening on port 4000
Make sure the DNS entry you created for
https://example.compoints to the correct port of the server running in hostmonster environment. Also, check the port on the firewall if it is accessible or blocked in hostmonster.You can check DNS ENTRY to make your DNS entry to the correct application and FIREWALL UPDATE.