Skip to main content
added 7 characters in body
Source Link
Ivan
  • 7.8k
  • 16
  • 86
  • 153

Differences between Node.js and React.js applications

I have a section of code in javascript that looks like this:

var fs = require('fs');

var subscriptions = []

var array = fs.readFileSync('optimal.csv', 'utf8').toString().split("\r");
for (i in array) {
    stock = array[i].split(':')[0];
    if (stock)
        subscriptions.push(stock)
}

When I say:

node .\realtime.js

it has no problem reading the file 'optional.csv'.

However, if I copy the same section of code to a react.js application built with create-react-app and try to run it, I get errors:

TypeError: fs.readFileSync is not a function

when I run it thus:

npm run start

var fs = require('fs');

// Grid data as an array of arrays
const quoteList = [];
var i = 0;
var stock;

var array = fs.readFileSync('optimal.csv').toString().split("\r");
    for (i in array) {
        stock = array[i].split(':')[0];
        if (stock)
            quoteList.push(stock)
    }
  • What is the correct way to read a .csv file from a purely react application?

Differences between Node.js and React applications

I have a section of code in javascript that looks like this:

var fs = require('fs');

var subscriptions = []

var array = fs.readFileSync('optimal.csv', 'utf8').toString().split("\r");
for (i in array) {
    stock = array[i].split(':')[0];
    if (stock)
        subscriptions.push(stock)
}

When I say:

node .\realtime.js

it has no problem reading the file 'optional.csv'.

However, if I copy the same section of code to a react.js application built with create-react-app and try to run it, I get errors:

TypeError: fs.readFileSync is not a function

when I run it thus:

npm run start

var fs = require('fs');

// Grid data as an array of arrays
const quoteList = [];
var i = 0;
var stock;

var array = fs.readFileSync('optimal.csv').toString().split("\r");
    for (i in array) {
        stock = array[i].split(':')[0];
        if (stock)
            quoteList.push(stock)
    }
  • What is the correct way to read a file from a purely react application?

Differences between Node.js and React.js applications

I have a section of code in javascript that looks like this:

var fs = require('fs');

var subscriptions = []

var array = fs.readFileSync('optimal.csv', 'utf8').toString().split("\r");
for (i in array) {
    stock = array[i].split(':')[0];
    if (stock)
        subscriptions.push(stock)
}

When I say:

node .\realtime.js

it has no problem reading the file 'optional.csv'.

However, if I copy the same section of code to a react.js application built with create-react-app and try to run it, I get errors:

TypeError: fs.readFileSync is not a function

when I run it thus:

npm run start

var fs = require('fs');

// Grid data as an array of arrays
const quoteList = [];
var i = 0;
var stock;

var array = fs.readFileSync('optimal.csv').toString().split("\r");
    for (i in array) {
        stock = array[i].split(':')[0];
        if (stock)
            quoteList.push(stock)
    }
  • What is the correct way to read a .csv file from a purely react application?
Source Link
Ivan
  • 7.8k
  • 16
  • 86
  • 153

Differences between Node.js and React applications

I have a section of code in javascript that looks like this:

var fs = require('fs');

var subscriptions = []

var array = fs.readFileSync('optimal.csv', 'utf8').toString().split("\r");
for (i in array) {
    stock = array[i].split(':')[0];
    if (stock)
        subscriptions.push(stock)
}

When I say:

node .\realtime.js

it has no problem reading the file 'optional.csv'.

However, if I copy the same section of code to a react.js application built with create-react-app and try to run it, I get errors:

TypeError: fs.readFileSync is not a function

when I run it thus:

npm run start

var fs = require('fs');

// Grid data as an array of arrays
const quoteList = [];
var i = 0;
var stock;

var array = fs.readFileSync('optimal.csv').toString().split("\r");
    for (i in array) {
        stock = array[i].split(':')[0];
        if (stock)
            quoteList.push(stock)
    }
  • What is the correct way to read a file from a purely react application?