0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you a
0:04
NodeJS script which automatically
0:06
converts your uh CSV file uh my CSV file
0:10
is located in the same directory uh it
0:12
is output dot CSV it has a array of
0:15
records here comma separated value it is
0:18
called so each column here this is your
0:21
one column ID name email age phone
0:24
number and these are the number of
0:26
records separated by comma that's why it
0:29
is called as commaepparated value and we
0:31
will now be writing a simple NodeJS
0:33
script which will convert all these
0:34
records into JSON file so if I just run
0:38
this script here on the left hand side
0:43
uh it will actually convert so we just
0:45
need to replace the file name here which
0:50
CSV and if you just run this you will
0:53
see CSV to JSON conversion complete and
0:56
you will see this JSON file been created
0:59
output dojson and you will see all your
1:06
records so I will show you uh this uh
1:09
package which in instantly do the
1:12
conversion for us so this is a third
1:13
party module CSV2 JSON just go to your
1:17
terminal just execute this command to
1:20
install this third party module i've
1:22
already done that so now I will show you
1:25
step by step how to do this so you first
1:28
of all need to require the file system
1:30
module which is a built-in module of
1:33
NodeJS and then we simply require this
1:36
third party module which is your CSV to
1:44
this so after that we simply call this
1:48
module CSV and it actually returns a
1:51
promise we can handle the promise and we
1:54
can chain a number of methods so from
1:58
file so you can you have three options
2:00
either you can input a file right here
2:03
or you can take the data from the stream
2:05
or a string we will basically take the
2:08
data from an input file name so my file
2:11
is located in the same directory so it
2:13
will be sample CSV so we are taking this
2:16
uh sorry this name name is output dot
2:21
CSV so we are taking this file name
2:24
converting it to JSON so it returns a
2:27
promise we can handle the promise using
2:30
dot then and all the data will be
2:34
converted and then it will be available
2:36
in this variable JSON and we can process
2:39
this by using this call back function
2:42
and here we can do the processing we can
2:49
file and here we can call this method
2:54
file synchronously and here we specify
2:58
the output file name which will be
3:00
do.json and then we convert the uh data
3:10
we format the data to a JSON format and
3:14
then we write a simple notification
3:17
that your file has been
3:20
converted CSV file successfully
3:23
converted to JSON so this is step 10
3:25
bystep script guys uh if I run the
3:28
script once again let me delete delete
3:32
this output file here before running the
3:40
so if I just run this script here you
3:43
will see CSV file converted to JSON
3:46
successfully converted to JSON and if I
3:48
open the JSON file you will see the CSV
3:52
file which is this file has been
3:55
converted so thank you very much for
3:57
watching this video and also check out
4:01
freemediatools.com which contains