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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:47:21+00:00 2026-06-10T21:47:21+00:00

I have the following basic script running in nodejs to serve up an html

  • 0

I have the following basic script running in nodejs to serve up an html file with an associated css stylesheet:

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

var serverPort = 8080;

var server = http.createServer(function(request, response) {

console.log('request starting ...');
var extname = path.extname(request.url);

var contentType = 'text/html';
    switch (extname) {
    case '.js':
        contentType = 'text/javascript';
        break;
    case '.css':
        contentType = 'text/css';
        break;
    }

fs.readFile('js/EmailDisplay/htm/index.html', function(error, content) {
    if (error) {
        console.log(error);
        response.writeHead(500);
        response.end();
    } else {
        console.log(contentType);
        response.writeHead(200, {'Content-Type': contentType});
        response.end(content,'utf-8');
    }
});
});

server.listen(serverPort);
console.log('Server running at localhost:' + serverPort +"/");

If I open the file in Firefox (File->Open File), it renders properly. If I go to localhost:8080 the index page is served but without the style applied to it. Why? The console.log in the fs.readFile block shows me that both files are being read.

PS – I know there are packages that will let me do this blindly (eg. ‘connect’) but I’m trying to understand what is actually happening before going that route.

  • 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-10T21:47:23+00:00Added an answer on June 10, 2026 at 9:47 pm

    The problem lies probably in this line:

     fs.readFile('js/EmailDisplay/htm/index.html', function(error, content) {
    

    You’re reading and returning to the client the same html file, even when .js and .css are requested.

    You should probably set the path to the file along its content type in the switch you have earlier in your code.

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

Sidebar

Related Questions

I have the following basic function: <script type=text/javascript> function Form_Data(theForm) { var t=1; while
I have the following fairly basic greasemonkey script: var newloc = location.href.replace(/^(.*)-xyz-(.*)$/i, $1$2); if
i have the following basic script to make an api call to vimeo and
I have the following jQuery (info from here http://www.threelas.com/2012/02/basic-blogger-json-feed-api.html ). the problem i am
I made a jsf project and have the following example from http://docs.openlayers.org/library/introduction.html but as
Say I have the following basic if-statement: if (A ~= 0) % do something
If I have the following basic C++ program: #include <iostream> using namespace std; class
I have come across the following basic Tree conflict: Local add, incoming add upon
I have the following assignment: Implement a basic shopping basket without using any predefined
I have the following mark up with a basic and advanced search divs. <div

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.