Warning
I implemented this for an interview once ages ago, but now it's unmaintained.
This is an implementation of Todo-Backend using Node and Express for the server, Knex for database migrations and query building, and some ES6+ features such as async/await. By default, this project configures Knex to save to PostgreSQL.
A production instance is running on Heroku.
Bonus features include a simple frontend boostrapped with create-react-app and the todo-backend specification tests transcribed for Jest--a quick full-stack starter pack.
-
Clone this repository.
git clone [email protected]:tonycheang/todo-backend-express-knex.git -
Install dependencies.
yarn install -
Create a postgres database for the project.
% psql postgres -U your_username_here postgres=> CREATE DATABASE name_of_db; postgres=> GRANT ALL PRIVILEGES ON DATABASE name_of_db TO your_username_here; postgres=> \q
You could change the default database, but Knex's .returning() method will only work for PostgreSQL, MSSQL, and Oracle databases. Modifications will be needed for other databases to meet the todo-backend spec.
-
Add Postgres credentials into server/.env to allow Knex to connect to the database.
-
Install Knex globally.
npm install knex -g -
Set up the database using Knex migrations.
cd server && knex migrate:latest -
Start the server on http://localhost:5000.
yarn server -
Test it against the spec at Todo-Backend Specs
-
Run tests locally using either.
yarn testyarn test:watchThe second command requires watchman
brew install watchman -
Install create-react-app frontend starting at root directory:
cd client && yarn install -
Run backend and frontend simultaneously from root directory.
yarn devNote: The proxied connection will only work locally. You'll need the server to serve the frontend build if you want to host the entire project somewhere.