I am trying to containerize my React application with docker and am now a little bit stuck with the server.js file as I do not know how to "implement" the application inside. I was able to simply show a "Hello World" but can't seem to run the application inside.

My idea was initially, that I could just use the index.js file as an entrypoint and use it in the "res.end(x)" as this was the place where I could simply enter the "Hello World".

Am I missing just something small or is my general approach wrong?

My server.js file looks as followed:

const http= require('http');
const fs = require('fs');
const index = fs.readFileSync('index.js');

let app = http.createServer((req, res) => {
res.writeHead(200,{'Content-Type': 'text/plain'});
res.end(index);
});

app.listen(9030, '0.0.0.0');
console.log('Node server running on port 9030')

Solution 1:

I share with you this best documentation : https://nodejs.org/en/docs/guides/nodejs-docker-webapp/