# Correct path for NODE\_EXTRA\_CA\_CERTS

**URL:** <https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437>\
**Category:** Support\
**Tags:** environment-vars\
**Created:** [November 17, 2021, 10:55am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437 "2021-11-17T10:55:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HansKre](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hanskre/32/31465_2.png) [@HansKre](https://answers.netlify.com/u/HansKre)\
**Post date:** [November 17, 2021, 10:55am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/1 "2021-11-17T10:55:34Z")

</div>

I am providing an intermediate certificate of a remote server through NODE\_EXTRA\_CA\_CERTS.

When I do this locally, it works wonderfully by just prepending the node-scripts: `"dev": "NODE_EXTRA_CA_CERTS='./certs/intermediate.pem' next dev",`

On netlify, I created the environment variable `NODE_EXTRA_CA_CERTS` with the value of `./certs/intermediate.pem`

But when I look into the logs of the serverless function which is making the fetch, I see the following warning:

`Warning: Ignoring extra certs from `./certs/intermediate.pem`, load failed: error:02001002:system library:fopen:No such file or directory`

Does anyone have an idea, how the remote path to the certificate should look like to not being ignored?

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [November 17, 2021, 11:09am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/2 "2021-11-17T11:09:52Z")

</div>

Hi @HansKre

If you have a directory called `certs` in the root of the git repository you are building from which contains the certificate(s), then you could try

```auto
NODE_EXTRA_CA_CERTS = '/opt/build/repo/certs/intermediate.pem'

```

as `/opt/build/repo` is the base directory builds are run in. You can also use [file based configuration](https://docs.netlify.com/configure-builds/file-based-configuration/) e.g.

```auto
[build.environment]
  NODE_EXTRA_CA_CERTS = '/opt/build/repo/certs/intermediate.pem'

```

I haven’t tried so can’t say for certain if this will work.

---

<div class="post-metadata">

**Author:** ![HansKre](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hanskre/32/31465_2.png) [@HansKre](https://answers.netlify.com/u/HansKre)\
**Post date:** [November 17, 2021, 11:39am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/3 "2021-11-17T11:39:34Z")

</div>

Thank you, @coelmay !

It is exactly as you assume:  
I have a directory called `certs` in the root of the git repository that I am building from and it contains the certificate(s).

I have setup `NODE_EXTRA_CA_CERTS` as you have suggested. Now I’m getting:

```auto
1:35:29 PM: Warning: Ignoring extra certs from `/opt/build/repo/certs/intermediate.pem`, load failed: error:02001002:system library:fopen:No such file or directory

```

Did I miss something?

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [November 17, 2021, 12:03pm UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/4 "2021-11-17T12:03:23Z")

</div>

That was probably my _best guess_ ☹

The only topics I can find along these lines refer to using SSH not certificates, like [[Support Guide] How do I access private repositories in the build environment?](https://answers.netlify.com/t/support-guide-how-do-i-access-private-repositories-in-the-build-environment/723) and [[Support Guide] Using an SSH key via environment variable during build](https://answers.netlify.com/t/support-guide-using-an-ssh-key-via-environment-variable-during-build/2457).

There is the possibility this isn’t possible. I can neither confirm nor deny. With luck a _Support Engineer_ (or other community member) can provide a solid answer.

---

<div class="post-metadata">

**Author:** ![HansKre](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hanskre/32/31465_2.png) [@HansKre](https://answers.netlify.com/u/HansKre)\
**Post date:** [November 18, 2021, 4:52am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/5 "2021-11-18T04:52:23Z")

</div>

I did some debugging and it turns out that if using `nextjs`, netlify-functions would run in ` /var/task/nextPage/pages/api`.

So I have moved certificate to `pages/api/intermediate.pem` and configured `NODE_EXTRA_CA_CERTS` as `NODE_EXTRA_CA_CERTS = /var/task/nextPage/pages/api/intermediate.pem` but it still doesn’t work for the same reason.

I also tried setting the permissions on the file:

```auto
sudo chown -R root certs
sudo chmod -R 644 certs/intermediate.pem

```

But that didn’t change anything either.

I tried to check `read access`:

```auto
    try {
      fs.accessSync(
        process.env.NODE_EXTRA_CA_CERTS as string,
        fs.constants.R_OK
      );
      console.log('can read');
    } catch (err) {
      console.error('no access!');
    }

```

And in the logs I get `no access`.

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [November 18, 2021, 5:17am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/6 "2021-11-18T05:17:11Z")

</div>

> [@HansKre](#):
>
> I did some debugging and it turns out that if using `nextjs` , netlify-functions would run in ` /var/task/nextPage/pages/api` .

You are trying to access/use this certificate in a function?

In that case, you won’t want to use an environment variable. You will need to `require` it in the function so it is bundled with the function at build time. E.g.

```auto
const cert = require('./certifice.pem');

```

Where `certificate.pem` is in the same directory as the function requiring it.

_(Note: I see in your original post you mention **serverless function**. Apologies.)_

---

<div class="post-metadata">

**Author:** ![HansKre](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hanskre/32/31465_2.png) [@HansKre](https://answers.netlify.com/u/HansKre)\
**Post date:** [November 18, 2021, 5:56am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/7 "2021-11-18T05:56:19Z")

</div>

That sounds very promising. How would I then use it with `fetch` though?

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [November 18, 2021, 6:24am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/8 "2021-11-18T06:24:07Z")

</div>

Perhaps this might help: [Client Side SSL in node.js with fetch](https://sebtrif.xyz/blog/2019-10-03-client-side-ssl-in-node-js-with-fetch/). While it uses `fs.readFileSync` to read the file, it might still work with `require`.

Again I can only speculate as I don’t have anything that requires access as you are attempting so have not attempted.

---

<div class="post-metadata">

**Author:** ![HansKre](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hanskre/32/31465_2.png) [@HansKre](https://answers.netlify.com/u/HansKre)\
**Post date:** [November 18, 2021, 10:47am UTC](https://answers.netlify.com/t/correct-path-for-node-extra-ca-certs/47437/9 "2021-11-18T10:47:02Z")

</div>

Many thanks for all your help, @coelmay.  
It looks like `netxjs` is not shipping the whole folder-content, so the certificate gets removed during build process (or not being shipped, depends on how you see it). So I don’t even get this approach to work in my local environment, unfortunately.

Regardless, thank you so much for all your effort!
