You can create a very simple web server using node.js
const http = require('http');
http.createServer((request, response) => {
const { headers, method, url } = request;
let body = [];
request.on('error', (err) => {
console.error(err);
}).on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();
// At this point, we have the headers, method, url and body, and can now
// do whatever we need to in order to respond to this request.
});
}).listen(8080); // Activates this server, listening on port 8080.
2
Answers
Why would you use apache web server and node.js?
You can create a very simple web server using node.js
If you’re thinking on using Node.js there are plenty of framework to use, such as Express, Hapi, Resitfy, Fastify etc…
hope that’s help.
You need “reverse proxy” to achieve this.
With config like:
Replace 8888 with the real port your nodejs app listening.
Check apache’s guide here: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html.
Also, check another related question: How to run nodejs application in apache server