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

The Archive Base Latest Questions

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

Okay so basically I am building an application for JavaScript development using Node. My

  • 0

Okay so basically I am building an application for JavaScript development using Node. My issue that keeps arising is when the server starts.

var host = '127.0.0.1',
    port = 8080;

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

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    var buffer = new Buffer(100);
    res.end(fs.read('index.html'));
}).listen(port, host);
console.log('Server running at http://' + host + ':' + port);

My issue lies with res.end(fs.read(‘index.html’)); I want the server to run that html document when a connection is made in the browser. I always get this error response in the console.

buffer.js:236
        throw new Error('First argument needs to be a number, ' +

Error: First argument needs to be a number, array or string.
    at new Buffer (buffer.js:236:15)
    at Object.fs.read (fs.js:348:14)
    at Server.<anonymous> (C:\Users\myname\Desktop\app\bin\server.js:45:20)
    at Sever.EventEmitter.emit (events.js:96:17)
    at HTTPParser.parser.onIncoming (http.js:1807:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at Socket.socket.ondata (http.js:1704:22)

My question is, how do you display an html document in the web browser when a connection is made to the server? Any help is appreciated. Thanks.

  • 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-16T03:55:13+00:00Added an answer on June 16, 2026 at 3:55 am

    Your code raises a few questions but if I understand your requirement this is what you need:

    You need to write the result of the file to the response stream as you see below.

    var host = '127.0.0.1',
        port = 8080;
    
    var fs = require('fs'),
        http = require('http');
    
    http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        fs.readFile('index.html',function(err,data){
            res.write(data);
            res.end();
        });
    }).listen(port, host);
    
    console.log('Server running at http://' + host + ':' + port);
    

    Of course this has no error checking etc but will get you going.

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

Sidebar

Related Questions

Okay so the basically I'm building an application to connect to xero on the
Okay basically I have an MFC application with lots of dialogs that need to
Okay, so I am basically making a script to pass post data using cURL.
I'm building a Zend-based Web app that will permit third-party extensions. Essentially, this application's
Okay so basically : i have this simple example: main.cpp using namespace VHGO::Resource; std::list<BaseTable*>
 Okay, so emoji basically shows the above on a computer. Is that another
Okay so basically i'm trying to submit a form with some javascript arrays. I
Okay basically I am creating a stored procedure that will return data for our
Okay, so I have this class that basically acts as a manager of an
Okay so i have a packed a proprietary binary format. That is basically a

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.