Nodejs and wamp server confusion

16,046

Node.js do not need to be installed with Apache. Node.js itself provide a server that would listen on a port. You can use Apache or Nginx to use proxy. You can run your application without these server also.

Create a file index.js using the code below and run node index.js

var http = require('http');
  http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

Open you browser and enter this url : http://127.0.0.1:1337/ You will see Hello World over there. In this case nodejs is listening on port 1337

Share:
16,046
Uzumaki Naruto
Author by

Uzumaki Naruto

Updated on June 04, 2022

Comments

  • Uzumaki Naruto
    Uzumaki Naruto almost 2 years

    The situation

    I have been developing in php and using wamp for the past 2 years. Then I come across a module to implement a chat system followed by instant notifications. So I go look it up and found this awesome "nodejs" that allows you to connect to connected users in realtime.

    This guy nodejs socket.io and php uploaded a way to integrate nodejs socket.io and php without node server. So I downloaded his project (github) and ran it on my computer but it gave connection refused error from 8080 So,

    I go to nodejs site and install nodejs on my system (windows). It automatically updated my environment variables and I could just go to my command line to run a example project as

    path(...)node nodeServer.js
    

    and then run the index file of the project from the shared link and it starts working. everything runs smooth and nice.

    MY QUESTION

    If without installing nodejs on my system I cannot run the node app in the small example project then how am I supposed to install nodejs on live server (apache) and use command line to start nodejs.

    I know this might be too silly but I am really new to nodejs so I don't know if I can run node on live php server. If it is possible then can anyone tell me how can I do that ? or is it just an ideal situation and can't be done.