I noticed in my project solution file explorer a new folder in the config folder called env
and it contains a subfolder production
with a file database.js
:
[project name]\config\env\production\database.js
The file content looks like the below:
// path: ./config/env/production/database.js
module.exports = ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: env('DATABASE_HOST'),
port: env.int('DATABASE_PORT'),
database: env('DATABASE_NAME'),
user: env('DATABASE_USERNAME'),
password: env('DATABASE_PASSWORD'),
ssl: {
ca: env('DATABASE_CA')
},
},
debug: false,
},
});
I believe this was created when following the Application Configuration deployment steps, as I executed the following command to build the project for production:
NODE_ENV=production npm run build
I’m not sure if the subfolder production
with file database.js
was created immendiately after executing the preceding build command for production, because immediately after, I executed the following command to run the server with the production settings (to which it failed resulting in the error outlined in the original post):
NODE_ENV=production npm run start
Either way, I think that preparing the application for production using the preceding execution commands, by default, creates a subfolder production
with a file database.js
in the path ./config/env/production/database.js
, thereby setting postgres as the default production database.
I had to download Postgres which installed pgAdmin alongside it.
Then I had to make sure that the connection is using the right environment variables from the .env file:
[project_folder]\backend.env
The following is the content of this file after I got it working:
HOST=0.0.0.0
PORT=1337
APP_KEYS=[my-key]
API_TOKEN_SALT=[my-api-token-salt]
ADMIN_JWT_SECRET=[my-admin-jwt-secret]
JWT_SECRET=[my-jwt-secret]
APP_HOST=0.0.0.0
NODE_PORT=1337
# Database postgres
DATABASE_CLIENT=postgres
DATABASE_HOST=127.0.0.1
DATABASE_PORT=5432
DATABASE_NAME=[my-database-name-as-defined-when-opening-and-setting-up-pgAdmin 4]
DATABASE_USERNAME=[my-database-username-as-defined-when-opening-and-setting-up-pgAdmin 4]
DATABASE_PASSWORD=[my-password-as-defined-when-opening-and-setting-up-pgAdmin 4]
DATABASE_SSL=false
Then make sure the connection is correct in config\env\production\database.js. The following is the content of this file after I got it working:
// path: ./config/env/production/database.js
module.exports = ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: env('DATABASE_HOST'),
port: env.int('DATABASE_PORT'),
database: env('DATABASE_NAME'),
user: env('DATABASE_USERNAME'),
password: env('DATABASE_PASSWORD'),
ssl: false
// ssl: {
// ca: env('DATABASE_SSL')
// },
},
debug: false
},
});
Now when executing the command: NODE_ENV=production npm run start
, there is no errors in the terminal, and the following message displays:
One more thing…
Create your first administrator
by going to the administration panel at:
┌───────────────────────────┐
│ http://0.0.0.0:1337/admin │
However, when navigating to this url, the browser does not load the page. Instead, it displays the error message:
This site can’t be reached
The web page at http://0.0.0.0:1337/admin might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID
I will probably make this into a new post/question.