I’m working on a project where I need to integrate a Flutter project into a Node.js application. The Flutter project resides in a directory named public-flutter, while the package.json file of the Node.js application is located outside this directory.
Here’s the structure of my project:
project-root/
├── package.json
├── index.js
└── public-flutter/
├── ... // Flutter project files
I’m looking for guidance on how to configure my Node.js application to serve the Flutter project alongside the Node.js application. Specifically, I need help with:
Modifying the package.json file to handle this scenario.
Configuring the Node.js server to serve the Flutter project files.
Ensuring that both the Node.js application and the Flutter project work together seamlessly.
I’ve already tried [mention any attempts or approaches you’ve tried], but I’m encountering issues with [describe any errors or unexpected behavior you’re experiencing].
Any advice, suggestions, or examples on how to accomplish this integration would be greatly appreciated.
Current package.json content:
{
"name": "plant-tracker-front-end",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"express": "^4.19.2"
}
}
Current index.js content (Node.js server file):
const express = require('express');
const path = require('path');
const app = express();
// Serve Flutter project from the public-flutter directory
app.use(express.static(path.join(__dirname, 'public-flutter')));
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
Thank you in advance for your help!