Skip to content

Commit 2c19c7a

Browse files
authored
Updated language
Updated text flow
1 parent d71e57d commit 2c19c7a

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

getting_started/javascript-client/lesson_2.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
# Lesson 2 - Importing data from CSV using Javascript script
1+
# Lesson 2 - Importing data from CSV using JavaScript script
22

3-
## Creating the Javascript script
3+
## Creating the JavaScript script
44

5-
Let's start a new `.js` file [insert_data.js](insert_data.js). You can copy and paste the one we have in this repo or build one yourself. We will explain the one we have so you have an idea what it does.
5+
Let's start a new `.js` file called [insert_data.js](insert_data.js). You can copy and paste the one we have in this repo or build one yourself. We will explain the one we have so you know what it does.
66

7-
In the first half of the script, we have to manage and import the data form CSV. In Node.JS there is the [`fast-csv` package](https://www.npmjs.com/package/fast-csv) which can aid reading of CSV files.
7+
In the first half of the script we have to manage and import the data from the CSV. In Node.JS there is the [`fast-csv` package](https://www.npmjs.com/package/fast-csv) that helps reading of CSV files.
88

9-
First we will install the package:
9+
First, install the package:
1010

1111
```bash
1212
npm i fast-csv
1313
```
1414

15-
Now we will import it as well as some other packages:
15+
The script will import this package with some others:
1616

1717
```javascript
1818
const fs = require("fs");
1919
const path = require("path");
2020
const csv = require("fast-csv");
2121
```
2222

23-
Also we need to import `WOQLClient` which is the client that communitcate with the TerminusDB/ TerminusCMS:
23+
It will also import `WOQLClient` which is the client that communitcates with the TerminusDB/TerminusCMS:
2424

2525
```javascript
2626
const TerminusClient = require("@terminusdb/terminusdb-client");
2727
```
2828

29-
At the top of the script, we prepare a few empty objects and list to hold the data, we use objects cause the keys can be the `Employees id` for easy mapping:
29+
At the top of the script, we prepare a few empty objects and list to hold the data, we use objects as the keys can be the `Employees id` for easy mapping:
3030

3131
```javascript
3232
const contact_numbers = {};
3333
const addresses = {};
3434
const employees = [];
3535
```
3636

37-
The goal is to populate the `employees` list with the `Employee` objects. To help, we also need `contact_numbers` to hold the contact numbers while reading the `Contact.csv`. The rest of the information in `Contact.csv` will be used to construct `Address` objects and stored in `addresses`. We store the id at first and make the linking later cause the manager of that employee may have not been "created" yet.
37+
The goal is to populate the `employees` list with the `Employee` objects. To help, we also need `contact_numbers` to hold the contact numbers while reading the `Contact.csv`. The rest of the information in `Contact.csv` will be used to construct `Address` objects and stored in `addresses`. We store the id at first and make the linking later because the manager of that employee may have not been "created" yet.
3838

39-
Then we go head and read the CSVs and do the corresponding data managing:
39+
Then we go ahead and read the CSVs and do the corresponding data managing:
4040

4141
```javascript
4242
// function to load and parse huge CSV files
@@ -103,11 +103,11 @@ const insertData = async () => {
103103
};
104104
```
105105

106-
Now, the `employees` list should be populated with the `Employee` objects that is ready to be insert into the database.
106+
The `employees` list should now be populated with the `Employee` objects, ready to be inserted into the database.
107107

108-
## Using the Javascript client
108+
## Using the TerminusDB JavaScript Client
109109

110-
The next step is the insert all `Employees` into the database. But before, we need to create a client with our cloud endpoint:
110+
The script inserts all `Employees` into the database using the TerminusDB JavaScript Client. To do this, we need to create a client with our cloud endpoint:
111111

112112
```javascript
113113
// TODO: Change teamname and username
@@ -123,9 +123,9 @@ const client = new TerminusClient.WOQLClient(
123123
client.setApiKey(process.env.TERMINUSDB_ACCESS_TOKEN);
124124
```
125125

126-
If you are using TerminusCMS, you can find the information of your endpoint, team, and API token from the [TerminusCMS dashboard](https://dashboard.terminusdb.com/) under profile.
126+
If you are using TerminusCMS, you can find the your endpoint, team, and API token in the [TerminusCMS dashboard](https://dashboard.terminusdb.com/) under profile.
127127

128-
Now we are all ready, the last thing to do is to insert the documents:
128+
The last thing to do is to insert the documents:
129129

130130
```javascript
131131

@@ -139,21 +139,21 @@ client.addDocument(employees).then((res)=>{
139139

140140
## Running the script
141141

142-
Do back to our terminal, we can run the script. Make sure you are in the Node.JS environment that has `terminusdb-client` installed.
142+
Run the script in the terminal. Make sure you are in the Node.JS environment that has `terminusdb-client` installed.
143143

144144
```
145145
$ node insert_data.js
146146
```
147147

148-
To check if the data is insert correctly, we can use the `getDocument` function:
148+
To check the data was insert correctly, use the `getDocument` function:
149149

150150
```javascript
151151
const result = await client.getDocument({"as_list":true});
152152
console.log(result);
153153
```
154154

155-
Or if the data is on TerminusCMS, you can check it in the [TerminusCMS dashboard](https://dashboard.terminusdb.com/)
155+
Or if using TerminusCMS, you can check it in the [TerminusCMS dashboard](https://dashboard.terminusdb.com/)
156156

157157
---
158158

159-
[Move on to Lesson 3 - Update and import new data that links to old data](lesson_3.md)
159+
[Lesson 3 - Update and import new data that links to old data](lesson_3.md)

0 commit comments

Comments
 (0)