- Make sure your project is not inside another git repo.
- You should have a
.gitignore
file in your project root with the following in it.
.DS_Store
*.log
*.sqlite
node_modules
.swp
.env
tmp
- You should have a
.env
in your root with something similar to below content. (Make sure to change the database name) - Windows users might have a different connection string with their username and password.
DATABASE_URL='postgresql://localhost:5432/goodfoodhunting'
SESSION_SECRET ='mistyrose'
- Ensure your database environmental variables have been set up.
- Example below: Check if you have updated your port and secret key in server.js file.
const port = process.env.PORT || 3000;
app.use(
session({
secret: process.env.SESSION_SECRET || "mistyrose",
resave: false,
saveUninitialized: true,
})
);
- To start your application in the production environment:
- open your
package.json
file. - In the "scripts" section, add "start" key to include the command you want to use for starting your application. It should look something like this:
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
}
-
Go to https://render.com/ and sign up.
-
Log in and click
New
>Web Service
-
In the
Create a new Web Service
page, connect your repository from the list of repositories if your Render account has been linked to your GitHub account. -
If your GitHub account was not linked, link the public Git repository URL in the
Public Git repository
section. -
Add the
Name
for your app. -
Select the appropriate
Region
according to your location. -
Runtime
- SelectNode
-
Build Command
-npm install
-
Start Command
-npm start
-
Select the
Free
instance. -
Create Web Service.
-
In the navigation bar, click
New
>PostgreSQL
. -
Add the
Name
for your PostgreSQL database. -
Select the appropriate region as per
step 6
forWeb Service
. -
PostgreSQL Version
-15
-
Select the
Free
instance. -
Create Database.
- Go to your
Dashboard
and select your database. - Scroll down to
Connections
PSQL Command
is what you need to access the database through your CLI/Terminal.- Copy your
PSQL Command
and paste it in your CLI. - As your newly created database would be empty, you'll need to create the tables necessary as you did for your local PostgreSQL database.
- Example:
CREATE TABLE bread ( id SERIAL PRIMARY KEY, name TEXT, image_url TEXT, );
- In your PostgreSQL info page, copy the
Internal Database URL
- Go to your
Dashboard
and select your Web Service. - On the sidebar, click
Environment
. - Select
Add Environment Variable
. - Under
Key
, putDATABASE_URL
and paste theInternal Database URL
you copied from the database info as thevalue
. AddSESSION_SECRET
as the key and any value that you have provided for it in your app.
Run the psql connection string to connect to the production database like before and then run additional SQL lines.
Just push your code to Github and it will auto-deploy on Render. If that doesn't work, you can select "manual deploy" on Render's dashboard.
Click logs in your Render app's dashboard to see what errors have come up.