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 8605791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:55:39+00:00 2026-06-12T02:55:39+00:00

I’m trying to set up a simple chat using node.js (no express) and socket.io.

  • 0

I’m trying to set up a simple chat using node.js (no express) and socket.io. Problem is that Chrome gets stuck on my external includes in the html file, resulting in those files never getting included. I’m including a ccs file, and three javascript files. As suggested in answers to other related questions here on Stackoverflow, I checked my document’s MIME type by requiring the mime module and using the mime.lookup(url), which says ‘text/html’. I specifically set the returning header to 'Content-Type' : 'text/html' and even played around with setting it as ‘text/css’ and ‘text/javascript’ to no avail. As of now I have no idea what to try next. Please help!

chat.html:

<!DOCTYPE html>
    <html>
        <head>
        <title>CHAT</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="css/style.css" /> <!-- First line that Chrome complains about -->
        <script type="text/javascript" src="/socket.io/socket.io.js"></script> <!-- Second line that Chrome complains about -->
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
        <script type="text/javascript" src="chatClient.js"></script>
                    </head>
        <body>
        <h1>this shall be a chat</h1>
        </body>
    </html>

chatClient.js:

var socket = io.connect('http://localhost');

        var chatBox = document.createElement('div');

        chatBox.id = 'chatBox';

        socket.on('server', function (data) {
        console.log('Server says: ', data.message);

        socket.emit('client', { clientMessage : 'this is all I have to say, right now!' });
});

chatServer.js:

var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
fs = require('fs'),
mime = require('mime');

var url = __dirname + '/chat.html';
var mimeType = mime.lookup(url);

console.log(mimeType);

app.listen(8080);

function handler (req, res) {
    fs.readFile(url, function (err, data) {
    if (err) {
        res.writeHead(500);
        return res.end('Error loading chat');
    }

    res.setHeader('Content-Type', mimeType); // Sets the header to 'text/html'
    res.writeHead(200);
    res.end(data);
    });
}

io.sockets.on('connection', function (socket) {
    console.log('CHAT ONLINE');
    socket.emit('server', { message: 'hello world' });

    socket.on('client', function (data) {
    console.log('Client says: ', data.clientMessage);
    });
});

This is my absolute first time posting here so please let me know if there’s anything more I should have included to assist in your helping me with this problem.

  • 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-12T02:55:40+00:00Added an answer on June 12, 2026 at 2:55 am

    You’re setting mimeType during initialization based on one file that you might be sending out, rather than setting it based on the file that you’re actually sending out. That will cause any non-HTML files that you might send (e.g CSS or JS files) to go out with a misleading Content-Type header. You need to do the check inside your request handler.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.