hedkace
(hedkace)
March 19, 2025, 12:24pm
1
I have a react front end - which seems to be working and a express backend. The backend project is deploying but crashes. It seems to me that it is not loading a file in the root directory. I am attaching the code for loading the file and the code I added to the vercel.json file.
Is there something I need to change to get it to load? Is that the problem I am having?
Thank you.
const map = await new Promise((resolve, reject)=>{
tmx.parseFile('snowmap1.tmx', (err, loadedMap) => {
if(err) return reject(err)
resolve(loadedMap)
})
})
{
"version": 2,
"builds": [{ "src": "./index.js", "use": "@vercel/node"}],
"routes": [{ "src": "/(.*)", "dest": "/"}]
}
system
(system)
March 19, 2025, 12:24pm
2
If you’re having trouble deploying an Express app, this guide can help.
You can also ask v0 for suggestions tailored to your own project setup.
pawlean
(Pauline P. Narvas)
March 19, 2025, 2:24pm
3
Hi, @hedkace ! Welcome to the Vercel Community
Nothing immediately jumped out to me as an issue, could you share a minimal reproducible example with us?
I’ll also share this thread in case it’s helpful!
Getting started
Express.js is one of the most popular framework choices for building a backend using Node.js. If you are starting a new Express project and want to deploy it to Vercel, we recommend you to follow the Using Express.js with Vercel guide.
Common patterns
If you are coming from an existing project, we’ve put together this example repository to showcase the common development patterns for Express apps.
We recommend hosting your frontend application on a separ…
1 Like
hedkace
(hedkace)
March 19, 2025, 4:43pm
4
“could you share a minimal reproducible example with us?”
Yes. But I’m not sure what I should share. Do you want to see the source code or something?
Thank you.
pawlean
(Pauline P. Narvas)
March 19, 2025, 5:04pm
5
1 Like
hedkace
(hedkace)
March 19, 2025, 6:27pm
6
Okay. I tried to do that.
Here is the project: https://mre1.vercel.app/
The deployment: https://vercel.com/hedkaces-projects/mre1/2oi5w7scC1HfHDEdZnoY9CLe8ZHp
The github repo is here: GitHub - hedkace/mre1: Example
Any help would be appreciated. Thank you again for looking at this!
hedkace
(hedkace)
March 19, 2025, 6:28pm
7
for some reason, require was not working, so it said to use import instead. So I changed it to that for this example.
anshumanb
(Anshuman Bhardwaj)
March 20, 2025, 4:40am
8
Hi @hedkace , I was able to get your app working (try here ) with the following changes:
move the index.js
in api/index.js
file
remove legacy options from the vercel.json
update index.js
to correctly handle file paths
import express from "express";
import { parseFile } from "tmx-parser";
import { join } from "path";
// Create Express app
const app = express();
app.use(express.json());
// Helper function to parse TMX file using promises
async function parseTmxFile(filePath) {
return new Promise((resolve, reject) => {
parseFile(filePath, (err, loadedMap) => {
if (err) return reject(err);
resolve(loadedMap);
});
});
}
async function loadMap() {
try {
// Use a path relative to the function's directory
const filePath = join(__dirname, "..", "snowmap1.tmx");
mapCache = await parseTmxFile(filePath);
return mapCache;
} catch (error) {
console.error("Error loading map:", error);
throw error;
}
}
// Define routes
app.get("/test", (req, res) => {
res.json({ message: "test ok" });
});
app.get("/", async (req, res) => {
try {
const map = await loadMap();
console.log({ map });
res.json({
data: { version: map.version, width: map.width, height: map.height },
});
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
});
app.listen(3000, () => console.log("Server ready on port 3000."));
module.exports = app;
{
"rewrites": [{ "source": "/(.*)", "destination": "/api/index" }]
}
3 Likes
hedkace
(hedkace)
March 20, 2025, 6:48pm
9
Thank you very much! The server is not crashing anymore. I am still having some trouble though that did help me make some progress.
My new issue is this: i seem to not be able to access mongodb or use socketio. No idea what’s going on. I don’t think it’s a ip whitelist issue but I could be wrong.
Any ideas?
1 Like
anshumanb
(Anshuman Bhardwaj)
March 21, 2025, 6:47am
10
Hi @hedkace , I’m glad you got it working.
About the Atlas issue: it is what the error says, your Atlas instance doesn’t know about Vercel. See this documentation to resolve it.
1 Like
hedkace
(hedkace)
March 25, 2025, 4:18pm
11
Thank you! I couldn’t look at it for a few days there, but I just followed that link and it is working for logging in.
I have one more issue. I am trying to use socket.io and that seems to be the only thing left to fix.
Does vercel let you use web sockets?
amyegan
(Amy Egan)
March 25, 2025, 9:24pm
12
Yes! We have a list of providers who can help you integrate realtime communication in your functions
2 Likes
system
(system)
Closed
April 1, 2025, 9:25pm
13
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.