- cd into
/api
and runnpm i
to install dependencies - create
.env
file in/api
folder with the environment variablesPORT=
server port (e.g. 3000),DB_URL=
postgres db connection string - database must have PostGIS extension installed - add your Mapbox API key to
client/index.js
- cd into
/api
- run
npm run setup-db
to setup the database - run the server with
npm run dev
- Create account with username and password on Render.com
- Click on the new button and choose Web Service
- Connect Render.com with your Github repository
- Select specified repository your project is located
- Name your site
- Select region closest to where your project will be accessed
- Choose branch to deploy
- Select Root Directory ie
/api
to deploy - In this case we will use Node as a runtime environment
- Build command depending on you
packge.json
file. - Use concatination to carry out multiple build commands at once ie.
npm i -D && npm run setup-db
- Finally Start command to deploy your project will be
node index.js
. - Click on Create Web Service.
- connect Render.com with Github repository
- Select specified repository
- Name your site
- Choose branch to deploy
- choose Root Directory ie.
/client
- Leave build command empty as render build automatically for us
- Publish directory will be current directory so use
.
to specify current directory. - Click on Create Static Site button to deploy your static site.
So far we have been running our server localy helce we used this fech command:
const response = await fetch("http://localhost:3000/users/#", options);
conecting to our local server.
Now that our server is hosted by and deployed on Render.com, To establish a connection between front end and backend server, we will use server URL for all fetch
requests on our front end.
a good example of this is replacing:
const response = await fetch("http://localhost:3000/users/#", options);
with:
"https://<your Web Services URL>/users/#",
once all fetch
requrestes are updated, your connection with the server will be established.