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

  • Home
  • SEARCH
  • 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 6903911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:59:04+00:00 2026-05-27T07:59:04+00:00

This is really weird problem. I just installed Node.JS on my system (Fedora). I

  • 0

This is really weird problem. I just installed Node.JS on my system (Fedora).

I have three files in /var/www/mirror/:

  • server.js
  • client.js
  • index.html

File server.js is the one I call via CLI: node server.js.

It, basically, returns index.html.

var
    http = require('http'),
    io   = require('socket.io'),
    fs   = require('fs');

http.createServer(function(request, response) {

    fs.readFile(__dirname + '/index.html', function(error, data) {

        if (error) {

            result.writeHead(500);

            console.log('Error: Could not read index.html.');

        }

        response.writeHead(200, {'Content-Type': 'text/html'});
        response.end(data);

    });

}).listen(1337, '127.0.0.1');

console.log('Server is running.');

All works as expected and no errors are thrown anywhere.

In index.html I have simple HTML5 structure (nothing unnecessary, really!) and <script /> that points to, already mentioned, client.js.

That line of code looks like this (Ctrl + U; from browser):

<script src="client.js"></script>

By moving cursor on client.js, I got actual location: http://127.0.0.1:1337/client.js.

Seems correct, right?

The problem:

By opening that link it opens wanted file, but the content is as server.js should return.

This disallows me from including any internal scripts and style-sheets!

I guess that anything that goes via http://127.0.0.1:1337/ (also http://127.0.0.1:1337/client.js, http://127.0.0.1:1337/a/b/c etc.) is handled via server.js – and server.js returns index.html (see above).

How can I fix it? Thanks in any advice!

  • 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-05-27T07:59:04+00:00Added an answer on May 27, 2026 at 7:59 am

    Look at the req.url to tell you the url that the user is requesting. From there, you have to have some code decide whether to serve index.html or client.js.

    Also, since I’m guessing index.html isn’t changing very frequently, you should probably just read it once, and store the buffer in a variable, rather than reading it on every request.

    There are some modules that make serving static files a bit easier. Check out filed for a pretty nice standalone static file

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

Sidebar

Related Questions

This is a really weird problem that I have been having. When I download
I have this really weird problem with my MySQL table. After some time a
I have this really weird problem in my code (.Net Framework 3.5). So, in
Ok, this is a really weird one. I have an MPI program, where each
I'm running into a really, really, really weird problem with mysql. I have a
I have run into this problem a lot in the past, but never really
ive got a really weird problem. i have no clue why its not working.
I have this really weird bug. When I scroll down my table view, down
I have a really weird problem with background worker. Code is too complicated so
I have a pretty weird problem related to zend framework's zend_db. I use $this

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.