Thursday 27 April 2017

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.

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...');
});



via Atul Kumar

No comments:

Post a Comment