ExpressJS boilerplate (modified and created by myself)
- Before installing, please specify database url in .env file (example env file on .env.example)
- Install all required things, use install.bat (double click it like executable)
- OR you can just run these command below (sequentially)
npm i --production=false
npx prisma migrate reset --schema=./models/schema.prisma -f
npx prisma db pull --schema=./models/schema.prisma
npx prisma generate --schema=./models/schema.prisma
- Installation will take a while, so please be patient.
- Make sure Installation is successful or done properly.
- Then you can run with run.bat (double click it like executable), OR you can just do
npm start
- Install all required things, follow the instruction above
- Open deploy-migration.bat to reset all data inside database
- Open unit-test.bat (double click it like executable)
- OR you can just run these command below
npx jest --runTestsByPath=tests
- Unit test will take a while, so please be patient.
- Go to gitlab project settings -> CI/CD
- Expand variables -> Add variables, and add these variables (key=value)
- DATABASE_URL=postgresql://randomuser:randompassword@postgres:5432/mydb?schema=public
- HEROKU_API_KEY=REPLACE_WITH_YOUR_KEY
- HEROKU_APP_NAME=REPLACE_WITH_YOUR_APP_NAME
- POSTGRES_DB=mydb
- POSTGRES_USER=randomuser
- POSTGRES_PASSWORD=randompassword
- Done, you can now push your code to gitlab and CI/CD runner will run without any problem
- Go to github repo settings -> Secrets -> Actions
- Add these variables (key=value)
- DATABASE_URL=postgresql://randomuser:randompassword@localhost:5432/mydb?schema=public
- HEROKU_API_KEY=REPLACE_WITH_YOUR_KEY
- HEROKU_APP_NAME=REPLACE_WITH_YOUR_APP_NAME
- HEROKU_EMAIL=REPLACE_WITH_YOUR_EMAIL
- POSTGRES_DB=mydb
- POSTGRES_USER=randomuser
- POSTGRES_PASSWORD=randompassword
- Done, you can now push your code to gitlab and CI/CD runner will run without any problem
MVC with Router and auto-generated Models
└── root
├── bin/
├── controllers/
│ ├── API/
│ └── web/
├── middlewares/
│ └── index.js
├── models/
│ └── prisma.schema
├── public/
│ ├── css/
│ ├── js/
│ └── images/
├── routes/
│ ├── api.js
│ └── index.js
└── views/
-
bin:
contains all the executables (you don't need to touch this folder)
-
controllers:
contains all the controllers
separated by API and web
-
middlewares:
contains all the middlewares
register your middlewares here inside function in index.js
-
models:
contains all the models (you don't need to touch this folder, but you can add your models here)
is automatically generated by prisma (see explanation below)
-
public:
contains all the static files
these files are served by the server
-
routes:
contains all the routes
register your API routes in api.js
register your web routes in web.js
-
views:
contains all the views
- prisma automatically generates a model for each table in your database when you run
npx prisma pull
- the model is automatically generated by prisma (depends on your database)
- generated models are stored inside prisma.schema in models folder
- more https://www.prisma.io/docs/getting-started