1

I want to read the .nrp extension file in Node JS. this is my node js code below.

    var fs = require('fs')

    fs.readFile('Jun24_Jun30.nrp','utf8', function(err, data) {
     if (err) throw err
     console.log(data)
    })

The output is coming as junk values when I try to read from node js.

Node js Output: enter image description here

But if I try to read the same file in C++ I am getting the correct Output.

this is my C++ code below.

    #include <iostream>
    #include <stream>
    using namespace std;

    class ValueGet {
    public:
    int data;
    ValueGet() {
    data = 0;
    }
   };
   int main()
   {
    ValueGet vg;
    ifstream file;
    file.open("Jun24_Jun30.nrp", fstream::binary | fstream::out);
    if (!file)
    cout << "File Not Found." << endl;
    else {
    file.seekg(0);
    while (file.read((char *)&vg, sizeof(vg)))
        cout<<vg.data<<endl;
}
//system("pause");
return 0;
}

C++ Output:

enter image description here

I want the same output from node js also. Please help.

Thanks!

1

1 Answer 1

-2

Try doing parsing the data or stringfy the data so that i may come up to human readable form. Thanks, i hope it will work.

    var fs = require('fs')          

    fs.readFile('Jun24_Jun30.nrp','utf8', function(err, data) {
    if (err) throw err
    else{
    console.log(JSON.parse(data))   //try JSON.parse(data) 
     }                              // JSON.Stringify(data)

    })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.