Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

404
Views
Run apache server and node on same port

I am using MAMP server and node js.

My issue is that I want to run apache server and node on the same port, but solutions online are quite complicated as it does not server much of the purpose, also I am new to Node. I need a simple solution where I can node on the port of apache server.

Code is below,

it works fine, as everything is running on different port but I want the 'server' to run on port 8888 where apache is running. Or some way for node to interact with apache

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var mysql = require('mysql');
var router = express.Router();

var connection = mysql.createConnection({
    host : 'localhost',
    user : 'root',
    password : 'root',
    database : 'db',
    port : '8889'
});

server.listen(8888); <----- ERROR
console.log('server running.......');

connection.connect(function(error){
    if(!!error) {
        console.log('error in db connection');
    } else {
        console.log('db connected');
    }
});

app.use('/*', router);

router.get('/*', function (req, res) {
    console.log('hello there...');
});
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I think the proper way to do this is to 'face' the Node service using Apache's Proxypass. This will forward a path to the node service running on a different port.

Adding the following to a your httpd.conf or under a vhost and restarting Apache should give you a working result

#I'm using 8890 for Node since your Apache runs on 8888 and DB is on 8889
ProxyPass /node/ http://localhost:8890/
ProxyPassReverse /node/ http://localhost:8890/

Navigating to http://localhost:8888/node/ will connect you to the node service running on port 8890.

over 4 years ago · Santiago Trujillo Report

0

You can use http-proxy for that.

var http = require('http'),
httpProxy = require('http-proxy'),
proxyServer = httpProxy.createServer ({
    hostnameOnly: true,
    router: {
        '127.0.0.1':        '127.0.0.1:8080'
    }
});

proxyServer.listen(8888);

This will create a node process listening to port 8888, and forwarding requested domains to 8080.

over 4 years ago · Santiago Trujillo Report

0

you will find many tutorials on this topic but here is a overview:

  • you need apache mod mod_proxy

  • basicly setup you need something like this, this link includes insturctions on how to set it up in a way, it will also forward your websockets (if you need that).

  • you will use somethink like, http://localhost:3005 where 3005 is the port nodejs runs on. (choose whatever port you like)

  • it might be usefull to add this port to you iptables to prevent direct access (without apache)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!