0

So I'm running this code from a node console and I need to put the result as a variable

 var csv = require('csv-array');
 csv.parseCSV("my.csv"
 , function(data){
   console.log(JSON.stringify(data));
 });

The array prints out fine, but how do I set the result as a variable? (I'm hoping this is as easy as it seems for someone with experience)

1
  • I'm not big on this whole js thing, care to elaborate? If you put it as an answer, you can grab an easy correct Commented Sep 10, 2017 at 1:03

1 Answer 1

1

Here you go,

 var csv = require('csv-array');
 //variable declaration
 var myVariable;
 csv.parseCSV("my.csv", function(data){
   myVariable = JSON.stringify(data);
   return data;
 });
 //take it as a variable here.
 console.log(myVariable);
Sign up to request clarification or add additional context in comments.

2 Comments

This was actually my issue in node. Thanks for the help though. stackoverflow.com/questions/14220321/…
so you just need to return data ? @thefett thank you

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.