Make sure you have Corepack installed and enabled. See Corepack - How to Install for more information.
$ corepack enable
Copy the .env.example
files to .env
files in both client and server folders, make adjustments if needed.
Afterwards, execute the following commands:
$ pnpm install
# Runs the needed docker containers
$ pnpm db:start
# Wipe out the DB (if present), (re)run all migrations, then seed the DB
$ pnpm server:migrate:reset
If this is the first time working on this project, make sure to read the following documents before starting to code:
# Runs the needed docker containers, only needed if you haven't run it already
$ pnpm db:start
# Open the following commands in 2 separate terminals
$ pnpm server:dev
$ pnpm client:dev
# Stops docker containers
$ pnpm db:stop
# Cleans all generated NestJS/GraphQL helpers, GraphQL schema, dist bundles, etc.
# Helpful when switching branches or when the client code generator fails
$ pnpm clean
# Generate all NestJS/GraphQL helpers and GraphQL schema which you'd need to run the app
$ pnpm generate
# Wipe out the DB (if present), re-run all migrations, then seed the DB
$ pnpm server:migrate:reset
Replace values into .env
with production ones, then execute the following commands:
# Clean all generated files, re-generate them anew, then build the app
$ pnpm build
# Serve the production build
$ pnpm serve
# You can now access the app on the URL specified into .env file
# If you're serving it locally, you can access it at http://localhost:3000 by default
This section is meant to describe the setup steps for a production installation of the software or anyway the installation on a machine that needs to be configured from scratch. It will list the minimal requirements needed to be able to install the code and make it run in production mode.
- Install Node.js version 18.20(LTS) or 20.12(LTS) on the server machine.
- Notice that if you do not have access to a graphical UI but just to a CLI, it is better to follow these instructions instead.
- Verify Node.js installation by running
node -v
in the terminal. It shall return its version. - From an elevated terminal (or using the
sudo
prefix on Linux/Mac), runcorepack enable
. This will make sure that Node.js can installpnpm
autonomously. - Install Docker according to the OS the app will run on.
- Make sure Docker is up and running properly. In the terminal run
docker -v
and it shall return the installed Docker version. - We recommend to not install Git on the production server in order to minimize installed apps.
- Download the code of this repository, then copy and move it into the desired location in the server machine. Use either
ftp
client or a.zip
file for this. - Once the files have been correctly uploaded to the server, update the server package
.env
file.- In the terminal run cd
packages/server
. - Copy and rename the file
.env.example
to.env
. - Open the
.env
file in edit mode. - Replace
NODE_ENV=development
withNODE_ENV=production
. - Use a tool like this one to generate a 32byte secret string (or also run
openssl rand -base64 32
command if installed in your machine or on the server). - Replace
APPLICATION_SECRET=secret
withAPPLICATION_SECRET=the_secret_generated_in_previous_step
. - Increase
TOKEN_EXPIRATION
however you like. Suggest4h
or8h
. - If a Facebook or Google login has been created to be linked to the app, set the correct
SOCIAL_CLIENT_ID
and respectiveSOCIAL_CLIENT_SECRET
. To create a social app and get the necessary configurations, please follow the instructions listed here. - Change
CLIENT_URL
andSERVER_URL
to your domain. It should behttps://www.ilmercatinodellibro.com
. Note that in this case you need to define the protocol (https://
) too. If you are using a different endpoint for the server than the client, make sure to replace it with the correct one. - Set
DB_USER
andDB_PASS
to a more secure value. Remember that if you change these after the database in docker has been created and seeded, the app may no longer be able to connect to the database. - Be sure to replace the values of all the different
MAIL_*
entries with the values provided you by your email provider. - Set
PUSH_NOTIFICATIONS_DRIVER=local
toPUSH_NOTIFICATIONS_DRIVER=void
- Set
OS_FILESYSTEM_PATH=path
to the folder path that you like. - Save and close this file.
- In the terminal run cd
- Now update the client package
.env
file as well.- Preferably in another terminal,
cd
intopackages/client
. - Copy and rename the file
.env.example
to.env
. - Open the
.env
file in edit mode. - Replace
DOMAIN
with the domain of your application. It should bewww.ilmercatinodellibro.com
. Notice that in this case you shouldn't include the protocol (https://
) since it will be added automatically. - If you have configured some options for social login, set either (or both)
FACEBOOK_LOGIN_ENABLED=true
andGOOGLE_LOGIN_ENABLED=true
according to your needs. - Save and close this file.
- Preferably in another terminal,
- In the terminal, go back to the root of the code, where this file is located.
- From there run
pnpm i
and wait until it completes. - Go back to the server folder
cd packages/server
and in there run:pnpm generate
to create GraphQL types.pnpm db:start
to crate Docker container for PostgreDB.pnpm migrate:reset
to reset database, run migrations and create the structure of the DB and finally seed the DB. Do not run this command when Mercatino is in production, or all the data will be lost!pnpm build
to prepare the server app- Now follow instruction inside the server's README.md to import books and schools.
- Now run
pnpm start:prod
to start the application of the server.
- Now, while the server is running in the other terminal, in the second opened terminal return to the
packages/client
directory:- Run
pnpm generate
. - Run
pnpm build
. This should copy the just built client into the server folder and thus it should already be accessible since the server is running.
- Run
- Make sure your web server is publishing the app on the correct port.
- Bonus tip: in order to be sure that the server is always running or that at least it gets restarted, we suggest to install and configure PM2 in order to restart the server process should it crash.