Not sure what to put for my build and deploy settings -> Most likely causing a 404 error

Github to my website:

I built a website using node.js, mongodb, and express.
My website allegedly deployed successfully, but when I followed the link given, I’m returned with a blank screen saying “not found”

Console:
Failed to load resource: the server responded with a status of 404 ()

I suspect the error is probably in my build and deploy settings, where I had absolutely no clue what to put for them.

Here are my settings:

Hi,

Your screenshot shows you’ve created a Static Site. If you want to use Express, you’ll need a Web Service. We have a basic guide on deploying Express apps: Deploy a Node Express App | Render Docs

Alan

Hey,

so I tried to deploy it on a web service, but when I click on the link I get a page saying

{“message”:“”,“name”:“AggregateError”,“stack”:“AggregateError\n at internalConnectMultiple (node:net:1114:18)\n at afterConnectMultiple (node:net:1667:5)”,“config”:{“url”:“http://localhost:3000/api/users",“method”:“get”,“headers”:{“Accept”:"application/json, text/plain, /”,“User-Agent”:“axios/0.21.4”},“transformRequest”:[null],“transformResponse”:[null],“timeout”:0,“xsrfCookieName”:“XSRF-TOKEN”,“xsrfHeaderName”:“X-XSRF-TOKEN”,“maxContentLength”:-1,“maxBodyLength”:-1,“transitional”:{“silentJSONParsing”:true,“forcedJSONParsing”:true,“clarifyTimeoutError”:false}},“code”:“ECONNREFUSED”}

Thanks for the quick reply!
owooji

That message has a localhost URL in there. If you’re deployed to Render, I guess you may want to reference your Render URL.

Alan

const app = express();

dotenv.config({
path: 'config.env'
});

const PORT = process.env.PORT || 8080;

// log requests
app.use(morgan('tiny'));
app.use(express.json())

// mongodb connection
connectDB();

// parse request to body-parser
app.use(bodyparser.urlencoded({
extended: true
}));

// set view engine
app.set("view engine", "ejs");

// load assets
app.use('/css', express.static(path.resolve(__dirname, "assets/css")));
app.use('/img', express.static(path.resolve(__dirname, "assets/img")));
app.use('/js', express.static(path.resolve(__dirname, "assets/js")));

// load routers
app.use('/', router);
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});

I see.
I believe they’re probably referencing how my server.js file is setup (code above).

I assume I would probably have to change

dotenv,config({
   path: 'https://ultideploy.onrender.com'
});

and maybe const PORT = 'https://ultideploy.onrender.com' or something of the sort?

Sorry, this is my first deployment so I’m still learning.

owooji

Specific app and code implementation is be beyond the scope of our support. Maybe other community members may be able to assist.

However, you mention the error occurs when you click on something, so I’m assuming this is a front-end/client side issue. At a guess you have some Javascript hardcoded to http://localhost:3000/ which would need to be updated to your deployed URLs.

Alan

Hopefully.

Asked on stack overflow, hopefully someone from there or here responds.

Oh, didn’t notice your repo was public and linked above.

It’s exactly what I suggested, you’re hardcoding your client-side calls to localhost: https://github.com/avi-kwok/coaching-application/blob/main/assets/js/index.js#L40

Alan

Solved the problem, server is live now. Thanks for your help!
The solution was keeping this in my server file:

dotenv,config({
   path: 'config.env'
});

and changing
const PORT = 3000
to
const PORT = 'https://ultideploy.onrender.com'

Will also have to change the hardcoded stuff too.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.