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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:46:44+00:00 2026-06-11T19:46:44+00:00

I just started using node js and I’ve moved one of my websites on

  • 0

I just started using node js and I’ve moved one of my websites on it:

var http    =   require('http');
var fs      =   require('fs');

var app = http.createServer(function (req, res) {

    fs.readFile('./index.html', 'utf-8', function(error, content) {
        res.writeHead(200, {'Content-Type' : 'text/html'});
        res.end(content);
    });
});
app.listen(8080);

The index.html is my website home page. With only html it works, but if i put tags in it (for including jquery for example), it gives JS errors in firebug : Uncaught syntax error : unexpected token < in jquery.js, and then of course ‘$ is undefined’.
It doesn’t load images either.

I don’t really need to do some routing or use Express framework or anything, it’s just a simple one-page website.
What am I doing wrong ?

  • 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-11T19:46:45+00:00Added an answer on June 11, 2026 at 7:46 pm

    Your server isn’t handling requests for images or other resources. All requests are given the same response of the ./index.html page.

    This means that if an external script or an image is included in the page, when a request is made by the browser for those resources, the original index.html page will be delivered instead.

    NodeJS is fairly low-level. You need to set up your server to manually handle requests for different types of resources based on the URL for each request.

    Your best bet will be to read through some NodeJS tutorials. They should cover the basics of serving content, though many of them won’t deal with the lower-level details, and will suggest packages like Connect or Express.

    Change your code to this, and you’ll see all the resources being requested.

    var http    =   require('http');
    var fs      =   require('fs');
    var url     =   require('url');
    var path    =   require('path');
    
    var app = http.createServer(function (req, res) {
    
        var pathname = url.parse(req.url).pathname;
        var ext      = path.extname(pathname).toLowerCase();
    
        console.log(pathname);
    
        if (ext === ".html") {
            fs.readFile('./index.html', 'utf-8', function(error, content) {
                res.writeHead(200, {'Content-Type' : 'text/html'});
                res.end(content);
            });
        }
    });
    app.listen(8080);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I just started out in node.js and when using REPL to require a
I've just started using node, I want to build a single page web app
I just started using Twitter Bootstrap http://twitter.github.com/bootstrap/scaffolding.html and I'm looking for the grey/blue navbar
just started using log4j in one of my home-projects and I was just about
I've just started with node.js and socket.io. I installed node.js using the windows installer,
Just started using carrierwave with Rails and things have been going smoothly with one
just started using JPA today, so i'm preety new to it. How would one
I just started using Eclipse but already I have a small problem. At first
I just started using rapidxml. I 1st create an xml file to read from.
I just started using Scala and Spec2. However, I'm a little bit confusing of

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.