osoc21 / technical-support

Technical Support
0 stars 1 forks source link

Hosting NodeJS with NestJs Framework #14

Closed ezer-i closed 3 years ago

ezer-i commented 3 years ago

@jbelien Everything works on localhost but then I tried with AWS elasticbeanstalk. The AWS link for the project aws elasticbeanstalk aws link response

jbelien commented 3 years ago

Hello @osoc21/the-tiny-troop , thanks for reaching out !

OKBE doesn't use AWS Elastic Beanstalk for our infrastructure. So I would recommend not to go that road.

What are your requirements ?

ezer-i commented 3 years ago

ooh great thanks for the response,...the environment is NodeJs, Postgres as Database and i have an env file for production if it's relevant.

jbelien commented 3 years ago

Perfect! 👌

Could you bundle everything in a Dockerfile ? If so, once the Dockerfile is ready, I'll deploy your project in one click using DigitalOcean App Platform in our OKBE account.

EDIT: If you need the database not to be reset each time you deploy. I can also add a PostgreSQL component in the App Platform (so you don't have to include it in your Dockerfile).

jbelien commented 3 years ago

UDATE: I just had a (quick) look at your repository and maybe going through Docker is not needed.

Can you confirm that if we build the backend in server/ folder with npm run build AND we build the frontend in client/ folder with yarn build AND I had a PostgreSQL database component you have everything you need ?

Side note: I see that in frontend/ you have both yarn.lock AND package-lock.json. Only one of those file should be there depending if you're using yarn or npm. Please delete the file that's not necessary.

ezer-i commented 3 years ago

Thanks for the update. We have corrected our files. we are using yarn and we have removed package-lock.jsonand we would like to deploy the server so we can use a single source for frontend (it contains a GraphQL link).

The code for server folder compiles very well but still in development.

We would like the server to be hosted to test our endpoint.

Thank you!

jbelien commented 3 years ago

I'll deploy client/ and server/ and create a PostgreSQL database tomorrow morning!

jbelien commented 3 years ago

Deployment is on its way! I'll let you know (here) when it's ready.

DigitalOcean App Platform configuration:

databases:
- engine: PG
  name: crowdy-db
  num_nodes: 1
  size: db-s-dev-database
  version: "12"
name: crowdy
region: ams
services:
- build_command: yarn build
  environment_slug: node-js
  envs:
  - key: DATABASE_URL
    scope: RUN_TIME
    value: ${crowdy-db.DATABASE_URL}
  github:
    branch: master
    deploy_on_push: true
    repo: osoc21/Crowdy
  http_port: 8080
  instance_count: 1
  instance_size_slug: basic-xxs
  name: crowdy
  routes:
  - path: /
  run_command: yarn start:prod
  source_dir: /server
static_sites:
- build_command: yarn build
  environment_slug: node-js
  envs:
  - key: DATABASE_URL
    scope: BUILD_TIME
    value: ${crowdy-db.DATABASE_URL}
  github:
    branch: master
    deploy_on_push: true
    repo: osoc21/Crowdy
  name: crowdy-app
  routes:
  - path: /crowdy-app
  source_dir: /client

Questions & Remarks:

jbelien commented 3 years ago

⚠️ Deployment is not possible at the moment: yarn start:prod command is failing! Please fix and ping me once it's fixed!

[2021-07-20 08:59:20] yarn run v1.22.10
[2021-07-20 08:59:20] $ node dist/main
[2021-07-20 08:59:20] internal/modules/cjs/loader.js:818
[2021-07-20 08:59:20]   throw err;
[2021-07-20 08:59:20]   ^
[2021-07-20 08:59:20] 
[2021-07-20 08:59:20] Error: Cannot find module '/workspace/server/dist/main'
[2021-07-20 08:59:20]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
[2021-07-20 08:59:20]     at Function.Module._load (internal/modules/cjs/loader.js:667:27)
[2021-07-20 08:59:20]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
[2021-07-20 08:59:20]     at internal/main/run_main_module.js:17:47 {
[2021-07-20 08:59:20]   code: 'MODULE_NOT_FOUND',
[2021-07-20 08:59:20]   requireStack: []
[2021-07-20 08:59:20] }
[2021-07-20 08:59:20] error Command failed with exit code 1.
[2021-07-20 08:59:20] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ezer-i commented 3 years ago

The command "start:prod": "node dist/main" is not working maybe because the dist folder appears after running "start": "nest start" for the first time .

That's where I think the problem is comming from.

But if the deployement requires only the server to run. On the node command to execute first, you might try "start": "nest start".

It's the only fix I am thinking in the moment.

jbelien commented 3 years ago

yarn start was the first thing I tried but it didn't work either.

Deployment runs sequentially yarn build then yarn start:prod. Can you check where yarn build generates its files (dist/ folder) ? And update start:prod script accordingly in your package.json file ?


The command "start:prod": "node dist/main" is not working maybe because the dist folder appears after running "start": "nest start" for the first time .

yarn build should generate dist/main.js.

jbelien commented 3 years ago

I just checked myself, you need to update your start:prod script in your server/package.json !

- "start:prod": "node dist/main",
+ "start:prod": "node dist/src/main",

Ping me once it's fixed!


You will also most probably let me know what are the environment variable you need. Reminder: the database connection URL is stored in DATABASE_URL environment variable, please update your code accordingly. It looks like this:

postgresql://my-database:my-password@app-98fc11a0-f17d-4436-9202-07607c080bec-do-user-1282652-0.b.db.ondigitalocean.com:25060/crowdy-db?sslmode=require
jbelien commented 3 years ago

Since this is not (really) going anywhere with App Platform I created a Droplet for your project so you can set it up as you need!

🚀

jbelien commented 3 years ago

@ezering Send me your public SSH key (or ask the person that will setup the server to send me his/her public SSH key) on Discord!

jbelien commented 3 years ago

Thank you @ezering and congratulations (again) for the deployment !