Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:39:58+00:00 2026-06-17T05:39:58+00:00

I wrote a minimalistic example of a server with node.js with which I want

  • 0

I wrote a minimalistic example of a server with node.js with which I want to get console notification that client connected. I am using following version of modules

  • express@3.0.6
  • socket.io@0.9.13
  • node@0.8.7

So I wrote this :

app.js

var socket = require('socket.io');
var express = require('express');
var http = require('http');

var app = express();

var server = http.createServer(app);

var io = socket.listen(server);
//var io = socket.listen(app);

io.sockets.on('connection',function(client){
        console.log("Client connected...");

        client.emit('messages', {hello: 'world'});
});

app.listen(8080);

index.html

<script src="node_modules/socket.io/lib/socket.io.js"></script>
<script>
    var server = io.connect("http://localhost:8080");

    server.on('messages', function(data){
        alert(data.hello);
    });

</script>

I have my catalog structure as follows:

|-- app.js
|-- index.html
`-- node_modules
    |-- express
    |   |-- bin
    |   |-- client.js
    |   |-- History.md
    |   |-- index.js
    |   |-- lib
    |   |-- LICENSE
    |   |-- Makefile
    |   |-- node_modules
    |   |-- package.json
    |   |-- Readme.md
    |   `-- test.js
    `-- socket.io
        |-- benchmarks
        |-- History.md
        |-- index.js
        |-- lib
        |-- LICENSE
        |-- Makefile
        |-- node_modules
        |-- package.json
        `-- Readme.md
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:39:58+00:00Added an answer on June 17, 2026 at 5:39 am

    Your line :

    <script src="node_modules/socket.io/lib/socket.io.js"></script>
    

    should be replaced with

    <script src="/socket.io/socket.io.js"></script>
    

    By doing this you are serving the static socket.io.js module for the client directly through socket.io’s internal static server and not by ExpressJS itself!

    EDIT 1 :

    Oh and I forgot to mention how to serve your index.html file so basically you need to set

    var app = express();
    
    app.use(express.static(__dirname + '/public'));
    

    and then place your index.html file in your /public directory

    EDIT 2 : ( explaination )

    ExpressJS serves static files through internal static file handler. The line app.use(express.static(__dirname + '/public')); actually reroutes your requests passed to node.js to your public folder.

    Socket.io on the other hand ( as a separate library ) has it’s own method to serve it’s static files and it is triggered only with GET request that contains URL : /socket.io/socket.io.js ( although there is another flash file .swf that is served for browsers that doesn’t support Websockets )

    You can learn more from the ExpressJS API and Socket.io wiki.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a process explorer using C with GUI interface. I want to add
I wrote a setter and getter method following Apple's conventions and noticed that despite
I wrote some test code that compares the speed of using the append() method
I wrote a macro that imports a CSV file into my spreadsheet, using a
I wrote a console program in c# that takes up to three files as
I wrote a function that tries to get a y/n (yes/no) answer from a
I wrote a PHP script that retrieves values from a MySQL Query. I used
I wrote a Flickr search engine that makes a call to either a public
I've been developing a minimalistic Java rich client CRUD application framework for the past
I wrote an application that use MKMapView. This application use a timer to update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.