# How to connect to Pinecone using Code node?

**URL:** <https://community.n8n.io/t/how-to-connect-to-pinecone-using-code-node/48007>\
**Category:** Questions\
**Tags:** node, code, pinecone\
**Created:** [June 6, 2024, 9:16pm UTC](https://community.n8n.io/t/how-to-connect-to-pinecone-using-code-node/48007 "2024-06-06T21:16:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonina](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@Antonina](https://community.n8n.io/u/Antonina)\
**Post date:** [June 6, 2024, 9:16pm UTC](https://community.n8n.io/t/how-to-connect-to-pinecone-using-code-node/48007/1 "2024-06-06T21:16:01Z")

</div>

Hi all!

I need to connect to the Pinecone vector store to perform different operations - for example, delete some vectors or completely delete all vectors from some index.

I can do this using simple python script:

```auto
import os
from pinecone import Pinecone
from dotenv import load_dotenv
load_dotenv()

# env var
api_key = os.getenv("PINECONE_API_KEY")

# init
pc = Pinecone(api_key)
index = pc.Index("my_index_name")

# clear the index if it contains vectors
if index.describe_index_stats().total_vector_count != 0:
    index.delete(delete_all=True)
else:
    print("The current index in the Pinecone vector store has no records.")

```

**How can I do the same using the `Code` node in n8n?**

I tried something like this to setup connection:

```auto
const Pinecone = require("pinecone-sdk");
const pineconeClient = new Pinecone.Client("MY_API_KEY", "MY_INDEX_NAME");
pineconeClient.connect();

```

However I get the error: “Problem in node ‘Code’. Cannot find module ‘pinecone-sdk’ [line 1]”.

I also tried setting environment variables to allow importing built-in and external modules:

```auto
export NODE_FUNCTION_ALLOW_BUILTIN=*
export NODE_FUNCTION_ALLOW_EXTERNAL=*

```

However I get another error: “Problem in node ‘Code’. ‘import’ and ‘export’ may only appear at the top level [line 1]”.

So, can someone help me implement the same logic as in my Python script but in the `Code` node?

## Information on n8n setup

- **n8n version:** 1.42.1 (Cloud)
- **Database (default: SQLite):** NA
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):** NA
- **Running n8n via (Docker, npm, n8n cloud, desktop app):** Cloud
- **Operating system:** NA

---

<div class="post-metadata">

**Author:** ![ThinkBot](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/thinkbot/32/62172_2.png) [@ThinkBot](https://community.n8n.io/u/ThinkBot)\
**Post date:** [June 7, 2024, 1:17am UTC](https://community.n8n.io/t/how-to-connect-to-pinecone-using-code-node/48007/2 "2024-06-07T01:17:18Z")

</div>

In order to use custom javascript packages you must be running n8n locally on your own server. Preferably via docker.

See here how to enable these external packages:

> **[Enable modules in Code node | n8n Docs](https://docs.n8n.io/hosting/configuration/configuration-examples/modules-in-code-node/)**
>
> Allow the use of both built-in and external modules within the Code node.

By setting this environment variable before starting.

`export NODE_FUNCTION_ALLOW_EXTERNAL=pinecone`

The above isnt javascript code, its “bash”, an environment variable, its entered via the command line/terminal when you setup via docker.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [September 5, 2024, 1:18am UTC](https://community.n8n.io/t/how-to-connect-to-pinecone-using-code-node/48007/3 "2024-09-05T01:18:09Z")

</div>

Closed on September 5, 2024, 1:18am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
