Skip to content

Commit 543e1f7

Browse files
committed
Herokuize project
* add build step to project * add dev script * instruct to use DATABASE_URL * put morgan in dependencies * inspired by https://github.com/babel/example-node-server/blob/master/package.json
1 parent ad11893 commit 543e1f7

File tree

4 files changed

+75
-26
lines changed

4 files changed

+75
-26
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
logfile
22

33
.env
4-
5-
node_modules/
4+
dist/
5+
node_modules/

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,24 @@ Client Applications:
4242
* `npm install`
4343
* fill out *.env file* (see below)
4444
* start PostgreSQL database
45-
* `npm start`
45+
* `npm run dev`
4646
* visit `http://localhost:8000` for GraphQL playground
4747

48+
## Deployment
49+
50+
Since we use modern javascript syntax, we need to perform a build step before
51+
deploying to production. The compiled API is put in `lib/`.
52+
53+
* provision postgres database
54+
* `npm run build`
55+
* `npm start`
56+
4857
#### .env file
4958

5059
Since this boilerplate project is using PostgreSQL, you have to install it for your machine and get a database up and running. You find everything for the set up over here: [Setup PostgreSQL with Sequelize in Express Tutorial](https://www.robinwieruch.de/postgres-express-setup-tutorial). After you have created a database and a database user, you can fill out the environment variables in the *server/.env* file.
5160

5261
```
53-
DATABASE=mydatabase
54-
55-
DATABASE_USER=postgres
56-
DATABASE_PASSWORD=postgres
57-
62+
DATABASE_URL=postgres://username:password@localhost:5432/mydatabase
5863
SECRET=asdlplplfwfwefwekwself.2342.dawasdq
5964
```
6065

package-lock.json

+55-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"node": "10.11.0"
88
},
99
"scripts": {
10-
"start": "nodemon --exec babel-node src/index.js",
10+
"start": "node dist/index.js",
11+
"build": "babel src --out-dir dist",
12+
"dev": "npm run build && nodemon dist/index.js",
13+
"heroku-postbuild": "npm run build",
1114
"test:run-server": "TEST_DATABASE=mytestdatabase npm start",
1215
"test:execute-test": "mocha --require @babel/register 'src/**/*.spec.js'",
1316
"test": "echo \"No test specified\" && exit 0"
@@ -16,15 +19,15 @@
1619
"author": "Robin Wieruch <hello@rwieruch.com> (https://www.robinwieruch.de)",
1720
"license": "ISC",
1821
"devDependencies": {
22+
"@babel/cli": "^7.2.3",
1923
"@babel/core": "^7.1.6",
2024
"@babel/node": "^7.0.0",
2125
"@babel/preset-env": "^7.1.6",
2226
"@babel/register": "^7.0.0",
2327
"axios": "^0.18.0",
2428
"chai": "^4.2.0",
2529
"mocha": "^5.2.0",
26-
"nodemon": "^1.18.7",
27-
"morgan": "^1.9.1"
30+
"nodemon": "^1.18.7"
2831
},
2932
"dependencies": {
3033
"apollo-server": "^2.2.3",
@@ -38,6 +41,7 @@
3841
"graphql-iso-date": "^3.6.1",
3942
"graphql-resolvers": "^0.2.2",
4043
"jsonwebtoken": "^8.4.0",
44+
"morgan": "^1.9.1",
4145
"pg": "^7.6.1",
4246
"sequelize": "^4.41.2",
4347
"uuid": "^3.3.2"

0 commit comments

Comments
 (0)