A micro-app to practice using Postgres with Node.js.
To help learn Postgres, the pg module and how to integrate them into an application.
Clone/fork the repo and then run: npm install
.
Create two empty folders views/helpers
and views/partials
(if you don't do this Handlebars/Vision may throw errors). These folders will be used for any Handlebars helpers or partials you might want to create.
Start the server npm start
, or to run it in dev mode: npm run dev
(requires nodemon). Remember nodemon won't recompile templates, so you'll need to restart the server if you amend any of the Handlebars templates.
-
The
Hapi
server is configured inserver.js
- you shouldn't need to alter this file. -
Environment variables are loaded using
env2
from a fileconfig.env
at the root (which is excluded from the repo via the .gitignore) -
Plugins are loaded from
plugins.js
, which just loadsVision
(you shouldn't need to change this) -
Handlebars is configured in
configure_handlebars.js
(you shouldn't need to change this) -
Routes are included as an array from
routes.js
(one default route included) -
The default Handlebars template is
views/layout/default.html
-
Handlebars templates are served from
views/
(seeroutes.js
for an example route which uses theviews/users.html
template)
-
Currently users are loaded from a static array in
routes.js
. Create a postgres database with some initial users (use the same data or create your own). -
Update the existing
/
route to load data from your new database instead of the array. -
Create a new user and add a route to create a new user (hint: think about which http method you should use to create a record)
-
Create a form to edit a user (you decide on how this will work on the front end) and a route to update an existing user.
-
Create a form to delete a user (you decide on how this will work on the front end) and a route to delete an existing user.
-
Update the database structure to hold additional information on each user (you choose, but try to pick information likely to be specific to a user - e.g. email address, home address etc)
-
Create a user detail view and a route which will read from the database and return all the data held for a particular user.
-
Let's refactor the database - create a new table holding user types. Add some additional fields which might be specific to a user type (use your imagination, but think about what data might be specific to a user type, as opposed to a user). Update the users routes to work with the new data structure.
-
Add routes to create, read, update and delete a user type. Think about what might happen if you try to delete a user type which is associated with a user. How should you deal with this?
-
Testing - if you haven't already done so, add some tests. Think about how your tests will work remotely (e.g. on a CI server).