How to fix Error: No certificates were found (TLS certificate not configured) in Node.js

Node.jsINTERMEDIATEHIGHUpdated Dec 22, 2025ยท 144 views

This error occurs when Node.js cannot locate the TLS certificate files required to establish a secure connection. It typically indicates missing, misconfigured, or inaccessible certificate paths in your HTTPS/TLS server setup.

Quick fix

Fixes ERR_TLS_NO_CERTIFICATES

# Check if files exist
ls -la /path/to/your/cert.pem
ls -la /path/to/your/key.pem

# On Windows, use dir instead
dir C:\\path\\to\\cert.pem
  1. Verify certificate files exist at the correct path
  2. Use absolute paths instead of relative paths
  3. Check file permissions
  4. Wrap file reading in error handling
node.js โ€” error
# Check if files exist
ls -la /path/to/your/cert.pem
ls -la /path/to/your/key.pem
# On Windows, use dir instead
dir C:\\path\\to\\cert.pem
Error: No certificates were found (TLS certificate not configured)

What this error means

The 'No certificates were found' error means Node.js tried to create a secure TLS context but could not find the certificate file(s) you specified. This happens when using tls.createSecureContext(), https.createServer(), or similar methods with TLS options. Node.js needs both a certificate (cert) and private key (key) file to establish encrypted connections. If these files are missing, have incorrect paths, or cannot be read due to permissions issues, this error is thrown.

Typical symptoms

  • HTTPS server fails to start with 'No certificates were found' error
  • Application crashes on startup when TLS options are configured
  • Error appears in console but TLS files exist on disk
  • Development environment works but production fails (path differences)
  • Certificate validation fails even though files appear to be present

Common causes

  1. Certificate or key file path does not exist or is incorrect (relative vs absolute path mismatch)
  2. File permissions prevent Node.js process from reading the certificate files
  3. Certificate file was deleted, moved, or renamed after configuration
  4. Working directory differs from where relative paths are resolved (different pwd when running vs expected)
  5. Path uses forward slashes on Windows or backward slashes on Unix-like systems
  6. Certificate file is in wrong format (binary instead of PEM) or corrupted
  7. Using relative paths without proper path resolution in your code

How to fix "Error: No certificates were found (TLS certificate not configured)"

1Verify certificate files exist at the correct path

First, confirm the certificate and key files are physically present on disk:

bash
# Check if files exist
ls -la /path/to/your/cert.pem
ls -la /path/to/your/key.pem

# On Windows, use dir instead
dir C:\\path\\to\\cert.pem

If files don't exist, you need to either generate them (for self-signed) or obtain them from your Certificate Authority.

2Use absolute paths instead of relative paths

One of the most common issues is using relative paths that may not resolve correctly. Always use absolute paths or construct them dynamically:

javascript
const fs = require('fs');
const https = require('https');
const path = require('path');

// BAD: Relative path
const options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem'),
};

// GOOD: Absolute path using path.join with __dirname
const options = {
  cert: fs.readFileSync(path.join(__dirname, '../certs/cert.pem')),
  key: fs.readFileSync(path.join(__dirname, '../certs/key.pem')),
};

// GOOD: Full absolute path
const options = {
  cert: fs.readFileSync('/etc/ssl/certs/cert.pem'),
  key: fs.readFileSync('/etc/ssl/private/key.pem'),
};
3Check file permissions

Verify that the Node.js process can read the certificate files:

bash
# Check current file permissions
ls -l /path/to/cert.pem
ls -l /path/to/key.pem

# Ensure the file is readable (owner must have read permission)
chmod 644 /path/to/cert.pem
chmod 600 /path/to/key.pem  # Key should be more restricted

# If running as a different user, ensure they own the files or belong to right group
chown nodeuser:nodeuser /path/to/cert.pem
chown nodeuser:nodeuser /path/to/key.pem

On Linux, the Node.js process must have read permissions for the certificate files.

4Wrap file reading in error handling

Add try-catch to get a clearer error message about which file is missing:

javascript
const fs = require('fs');
const https = require('https');
const path = require('path');

try {
  const cert = fs.readFileSync(path.join(__dirname, 'cert.pem'));
  const key = fs.readFileSync(path.join(__dirname, 'key.pem'));

  const options = { cert, key };
  const server = https.createServer(options, (req, res) => {
    res.writeHead(200);
    res.end('Hello HTTPS!');
  });

  server.listen(443, () => console.log('HTTPS server running'));
} catch (err) {
  console.error('Failed to load certificates:', err.message);
  process.exit(1);
}

This helps identify which specific file is missing.

5Validate certificate file format

Ensure your certificate files are in PEM format (text, not binary):

bash
# Check if certificate is in PEM format (should start with -----BEGIN)
head -1 /path/to/cert.pem
# Should output: -----BEGIN CERTIFICATE-----

# Check if key is in PEM format
head -1 /path/to/key.pem
# Should output: -----BEGIN RSA PRIVATE KEY----- or -----BEGIN PRIVATE KEY-----

If the file is binary or in DER format, convert it using OpenSSL:

bash
# Convert DER certificate to PEM
openssl x509 -inform DER -in cert.der -out cert.pem

# Convert DER key to PEM
openssl rsa -inform DER -in key.der -out key.pem
6Use environment-specific certificate paths

For production deployments, use environment variables for certificate paths:

javascript
const fs = require('fs');
const https = require('https');
const path = require('path');

const certPath = process.env.CERT_PATH || path.join(__dirname, 'cert.pem');
const keyPath = process.env.KEY_PATH || path.join(__dirname, 'key.pem');

try {
  const options = {
    cert: fs.readFileSync(certPath),
    key: fs.readFileSync(keyPath),
  };

  const server = https.createServer(options, handler);
  server.listen(process.env.PORT || 443);
} catch (err) {
  console.error(`Certificate loading failed: ${err.message}`);
  console.error(`Looked for cert at: ${certPath}`);
  console.error(`Looked for key at: ${keyPath}`);
  process.exit(1);
}

Then set environment variables in your deployment:

bash
export CERT_PATH=/etc/ssl/private/cert.pem
export KEY_PATH=/etc/ssl/private/key.pem

Advanced notes

Certificate Chain: If using a certificate signed by a Certificate Authority, you may need to include intermediate certificates. Use the ca option with an array of CA certificates:

javascript
const options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem'),
  ca: [fs.readFileSync('intermediate1.pem'), fs.readFileSync('intermediate2.pem')],
};

Self-Signed Certificates: For development, generate self-signed certificates using OpenSSL:

bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

Container Deployments: When using Docker, ensure certificate files are mounted as volumes or copied during the build. Common mistake is using a host path that doesn't exist in the container:

dockerfile
# In Dockerfile
COPY certs/ /app/certs/

# In docker-compose.yml
volumes:
  - ./certs:/app/certs:ro

Module Bundling: If using tools like webpack or bundlers, certificate paths become invalid after bundling. Always use environment-based paths or load certificates at runtime from the filesystem, never try to bundle certificate files.

Frequently asked questions

What does "ERR_TLS_NO_CERTIFICATES" mean?
js tried to create a secure TLS context but could not find the certificate file(s) you specified. createServer(), or similar methods with TLS options. js needs both a certificate (cert) and private key (key) file to establish encrypted connections.
How do I fix "ERR_TLS_NO_CERTIFICATES"?
This error occurs when Node.js cannot locate the TLS certificate files required to establish a secure connection. It typically indicates missing, misconfigured, or inaccessible certificate paths in your HTTPS/TLS server setup.
What causes "ERR_TLS_NO_CERTIFICATES"?
Certificate or key file path does not exist or is incorrect (relative vs absolute path mismatch) File permissions prevent Node.js process from reading the certificate files Certificate file was deleted, moved, or renamed after configuration
Is the "ERR_TLS_NO_CERTIFICATES" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading