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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:05:30+00:00 2026-05-28T07:05:30+00:00

New to NodeJS. Yes I know I could use a framework, but I want

  • 0

New to NodeJS.

Yes I know I could use a framework, but I want to get a good grok on it before delving into the myriad of fine fine tools that are out there.

my problem:

var img = fs.readFileSync(path);

the above works;

fs.readFile(path, function (err, data) 
        {
            if (err) throw err;
            console.log(data);
        });

the above doesn’t work;

the input path is : ‘C:\NodeSite\chrome.jpg’

oh and working on Windows 7.

any help would be much appreciated.

Fixed
Late night/morning programming, introduces errors that are hard to spot. The path was being set from two different places, and so the source path were different in both cases. Thankyou for your help. I am a complete numpty. 🙂

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

    If you are not setting an encoding when reading a file, you will get the binary content.

    So for example, the following snippet will output the content of the test file using UTF-8 encoding. If you don’t use an encoding, you will get an output like “” on your console (raw binary buffer).

    var fs = require('fs');
    
    var path = "C:\\tmp\\testfile.txt";
    fs.readFile(path, 'utf8', function (err, data) {
      if (err) throw err;
      console.log(data);
    });
    

    Another issue (especially on windows-based OS’s) can be the correct escaping of the target path. The above example shows how path’s on Windows have to be escaped.

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

Sidebar

Related Questions

I am new to NodeJS and Socket IO, I use PHP and jQuery. I
New to both Ruby and Rails but I'm book educated by now (which apparently
New to WCF, but familiar with COM+ - can I wrap a WCF service
I'm trying to use NodeJS with a C program to http://en.wikipedia.org/wiki/Setvbuf for JS files
EDIT: Yields that there is already new PHP framework written as extension. http://code.google.com/p/yafphp ,
When a request comes into a nodejs server, how does it handle the request?
Using Cradle 5.5 and NodeJS 0.4.8, I can't seem to get a connection to
I'm just barely getting into NodeJS a bit and have hit a snag trying
I don't know why it happens, but all elements of my array has same
I'm a new nodejs developer, and I think that I understand designs of nodejs.

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.