data-forge / data-forge-ts

The JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
http://www.data-forge-js.com/
MIT License
1.34k stars 77 forks source link

TypeError: dataForge.readFile is not a function #90

Closed tandavala closed 4 years ago

tandavala commented 4 years ago

What i am doing wrong?

I am reading the book data wrangling with javascript on chapter 5 we have a code i which is not working when i run it.

Here is the code

"use strict";

const dataForge = require("data-forge");

dataForge
  .readFile("./data/monthly_crashes-cut-down.csv")
  .parseCSV()
  .then((dataFrame) => {
    console.log(dataFrame.getColumnNames());
  })
  .catch((err) => {
    console.error((err && err.stack) || err);
  });

But when i run this code it is giving me the following error:

TypeError: dataForge.readFile is not a function
    at Object.<anonymous> (/home/tandavala/Documentos/Programming/Node/advanced/js-data-wragling/chap5/listing-5.6.js:6:4)
    at Module._compile (internal/modules/cjs/loader.js:1118:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1138:10)
    at Module.load (internal/modules/cjs/loader.js:982:32)
    at Function.Module._load (internal/modules/cjs/loader.js:875:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
ashleydavis commented 4 years ago

That function isn't included in the core Data-Forge library.

If you make your code import look like this it will work under Node.js (it doesn't work in the browser):

const dataForge = require("data-forge");
require("data-forge-fs");

Make sure you install data-forge-fs as well:

npm install --save data-forge-fs