$ git clone https://github.com/kdsuneraavinash/express-ts-api-template
Make sure you have yarn installed.(https://yarnpkg.com/)
Then Run yarn
to install dependencies.
$ yarn
Copy the .env.example
file to .env
file and change the values according to your environment.
Install postgres and setup it according to your OS instructions. Use following
command to login to the psql
shell.
$ psql -U postgres
Then enter below commands.
CREATE ROLE db_user WITH LOGIN PASSWORD 'password';
CREATE
DATABASE example_db;
GRANT ALL PRIVILEGES ON DATABASE
example_db TO db_user;
\q
Then login to psql
as db_user
and check if the setup is done correctly. Password should be password
.
psql -U db_user example_db
- Install postgresql in the local machine and setup correctly. Do not change default
port or other settings. Give a password to
postgres
user when asked. - Login to
pgAdmin
using the username and password give in the setup process. From theBrowser
panel, selectServer>postgres>Login/Group Roles
and right click and create the role. Givedb_user
as role name and givepassword
as the password. - Then right click
Server>postgres>Databases
and Create new database. Giveexample_db
as the database name and setdb_user
as the owner. - Then try to login to
psql
shell using default port, server, databaseexample_db
anddb_user
user.
First run the database migration and create the necessary tables. Make sure you are in the correct virtual environment. Whenever there is a database model change, you should re-run this.
$ npx prisma migrate dev
Then add the initial seed data.
$ npx prisma db seed
The default url for the API is http://127.0.0.1:8000/
$ yarn dev