How to put a password file into gitignore and distribute it

Hello!
I want to create two projects in Render, one for distributing Node.js source code and the other for creating PostgreSQL and linking the two.
The source code is distributed well, the database is created successfully, and the project is completed by linking the two.

As the connection information linking the database contains a password, I would like to place the “password_render.js” file in gitignore so that it cannot be tracked on GitHub.

However, when I do this, it works fine locally (since I can access the file), but in Render, an error occurs: “Cannot find module ‘./password_render.js’”. I tried using the “secret files” provided by Render, but it kept failing due to path problems.

If you know the solution, please give me some advice. Thank you.


  1. main.js
    const { pool } = require(‘./password_render.js’);

  1. password_render.js
    const { Pool } = require(‘pg’);
    const pool = new Pool({
    connectionString: ‘postgres://nodejs_crud_public2_db_user:PASSWORD@dpg-cnkq4c6n7f5s73b1ejrg-a.oregon-postgres.render.com:5432/nodejs_crud_public2_db?ssl=true’
    });
    module.exports = {
    pool
    };

HI,

A secret file sounds like the right solution here. What are the actual errors are you getting?

Alan

Thank you for the answer. I wasn’t sure about the exact way to use secret files, so I wrote it like this, but I’m still getting the same error: 'Cannot find module ‘./password_render.js’.


  1. main.js
    const { pool } = require(‘./password_render.js’);

  1. password_render.js
    const { Pool } = require(‘pg’);
    const fs = require(‘fs’);

const secretFilePath = ‘/etc/secrets/key’;
const secret = fs.readFileSync(secretFilePath, ‘utf8’).trim();

const pool = new Pool({
connectionString: secret
});

module.exports = {
pool
};


  1. secret files
    -filename:key
    -contents:postgres://nodejs_crud_public2_db_user:PASSWORD@dpg-cnkq4c6n7f5s73b1ejrg-a.oregon-postgres.render.com:5432/nodejs_crud_public2_db?ssl=true

Could you maybe share a screenshot of the secret files section of the “Environment” tab of the service. Not the contents, just how it’s setup in the dashboard.

Alan

However, these secret files are lost when you leave the page and come back. I don’t think it’s supposed to be written like this, but I don’t know how.

If your code is expecting the file to be called password_render.js, that should be the name of your secret file.

You don’t appear to have the “Save Changes” buttons in your screenshot, and the colors look a little off. Are you running a custom stylesheet or some sort of browser extension?

For example, my page looks like:

Alan

I did as you said and the distribution was successful!!
I’ve been struggling with this for a week, thank you so much.
This was my first deployment of my project and it gave me confidence.

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