# How to auto-import csv content into Neo4j

**URL:** <https://community.neo4j.com/t/how-to-auto-import-csv-content-into-neo4j/18128>\
**Category:** Neo4j Graph Platform\
**Created:** [May 5, 2020, 2:33pm UTC](https://community.neo4j.com/t/how-to-auto-import-csv-content-into-neo4j/18128 "2020-05-05T14:33:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kasperknudz](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/kasperknudz/32/4545_2.png) [@kasperknudz](https://community.neo4j.com/u/kasperknudz)\
**Post date:** [May 5, 2020, 2:33pm UTC](https://community.neo4j.com/t/how-to-auto-import-csv-content-into-neo4j/18128/1 "2020-05-05T14:33:39Z")

</div>

Hi! We are trying to receive a CSV file from frontend and create nodes from the CSV content. How do we get the neo4J to load the CSV code from javascript automatically when we receive a new CSV-file?

Currently we are thinking something like this to receive the file in frontend:

```auto
import fileUpload from "express-fileupload";
app.use(fileUpload());

//Upload endpoint
app.post('/upload', (req, res) => {
  if(req.files === null){
    return res.status(400).json({ msg: 'No file uploaded'});
  }
  const file = req.files.file;
  file.mv(${__dirname}/client/public/uploads/${file.name}, err => {
    if(err){
      console.error();
      return res.status(500).send(err);
    }
    res.json({ fileName: file.name, filePath: `/uploads/${file.name}`});
  })
})

```

---

<div class="post-metadata">

**Author:** ![tony.chiboucas](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tony.chiboucas/32/5980_2.png) [@tony.chiboucas](https://community.neo4j.com/u/tony.chiboucas)\
**Post date:** [May 5, 2020, 5:11pm UTC](https://community.neo4j.com/t/how-to-auto-import-csv-content-into-neo4j/18128/2 "2020-05-05T17:11:54Z")

</div>

You'll need to trigger a Cypher command, somehow. That could be an API method you add to Neo4j via a plugin. Though that's much trickier than you might think (I'm _almost_ ready to publish an open plugin like this). Before you go too deep, check the import guide:

> **[Tutorial: Import CSV data using LOAD CSV - Getting Started](https://neo4j.com/docs/getting-started/data-import/csv-import/)**
>
> This tutorial shows how to use the command LOAD CSV to import small to medium datasets in CSV format into Neo4j using Aura and on-premise deployments.

Your options:

- Plugin to tweak the api, and handle the upload.
- Driver on the server-side. Running Node.js as a middleman to provide the resource (server-side to handle the POST request) to receive and save the csv, then trigger the Cypher import command.
- Use the Bolt driver in the client, to trigger the Cypher import command.
  - You'd have to build a way to make the CSV file accessible to Neo4j. That can be a url to the file (with some Neo configuration tweaks), or the file can be put in the `$NEO_HOME/import` directory.
  - Alternatively, you could parse the CSV in the client, and convert it into a set of native Cypher commands that _would not_ require uploading the file.

### Cypher IMPORT

The _ **neo4j-javascript driver** _ ([docs](https://neo4j.com/developer/javascript/)) ([github](https://github.com/neo4j/neo4j-javascript-driver)) can be used server-side, or client-side. There are two Cypher utilities that can import CSV:

- [LOAD CSV](https://neo4j.com/docs/cypher-manual/current/clauses/load-csv/) - Native Cypher. Best for files \< 2MB in size.
- [apoc.load.csv](https://neo4j.com/docs/labs/apoc/current/import/load-csv/), or [apoc.load.json](https://neo4j.com/docs/labs/apoc/current/import/load-csv/) - Part of the Apoc plugin. Can handle just about anything when combined with [apoc.periodic](https://neo4j.com/docs/labs/apoc/current/graph-updates/periodic-execution/).

However, _both_ of these utilities require the file to already exist somewhere Neo can access.

### Client Affect

If you're _only_ building a javascript client, and you want the user to be able to create and upload the csv, then you're going to have to work some magic, and you have a few options:

- Use a intermediary storage location, have the client send the CSV there, resulting in a URL that Neo4j can access, then run the Cypher import command through the neo4j-javascript driver.
- Parse the csv in the client, and built the Cypher commands to MERGE/CREATE Nodes.

---

<div class="post-metadata">

**Author:** ![kasperknudz](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/kasperknudz/32/4545_2.png) [@kasperknudz](https://community.neo4j.com/u/kasperknudz)\
**Post date:** [May 6, 2020, 11:33am UTC](https://community.neo4j.com/t/how-to-auto-import-csv-content-into-neo4j/18128/4 "2020-05-06T11:33:30Z")

</div>

We are thinking of the option:

> Use a intermediary storage location, have the client send the CSV there, resulting in a URL that Neo4j can access, then run the Cypher import command through the neo4j-javascript driver.

and sessions would be the container that handles execution of cypher-queries into Neo4J when we drag and drop a CSV?

---

<div class="post-metadata">

**Author:** ![jggomez](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jggomez/32/7793_2.png) [@jggomez](https://community.neo4j.com/u/jggomez)\
**Post date:** [May 7, 2020, 2:31am UTC](https://community.neo4j.com/t/how-to-auto-import-csv-content-into-neo4j/18128/5 "2020-05-07T02:31:48Z")

</div>

Hi, I think that an easy solution could be to create a cloud function (for example with Firebase). This function can be triggered when a file is uploaded to storage. This function receives the file, processes and creates the nodes in neo4j. The function will run in background.

[https://firebase.google.com/docs/functions/gcp-storage-events](https://firebase.google.com/docs/functions/gcp-storage-events)
