This repo serves as the backend for the catalyst project.
The backend uses passport for authentication, express for the server, postgresql for the database, and sequelize for the ORM.
Make sure you read the FAQ for more details and info.
- Express.js as the web framework.
- ES2017+ support with Babel.
- Automatic polyfill requires based on environment with babel-preset-env.
- Linting with ESLint.
- Testing with Jest.
- Quick deployment guide for Heroku, AWS Elastic Beanstalk, and App Engine.
npm install
sequelize db:create
sequelize db:migrate
sequelize db:seed:all
Then you can begin development:
# npm
npm run dev
This will launch a nodemon process for automatic server restarts when your code changes.
Testing is powered by Jest. This project also uses supertest for demonstrating a simple routing smoke test suite. Feel free to remove supertest entirely if you don't wish to use it.
Start the test runner in watch mode with:
# npm
npm test
You can also generate coverage with:
npm test -- --coverage
### Linting
Linting is set up using [ESLint](http://eslint.org/). It uses ESLint's default [eslint:recommended](https://github.com/eslint/eslint/blob/master/conf/eslint.json) rules. Feel free to use your own rules and/or extend another popular linting config (e.g. [airbnb's](https://www.npmjs.com/package/eslint-config-airbnb) or [standard](https://github.com/feross/eslint-config-standard)).
Begin linting in watch mode with:
# npm
npm run lint
To begin linting and start the server simultaneously, edit the package.json
like this:
"dev": "nodemon src/index.js --exec \"node -r dotenv/config -r babel-register\" | npm run lint"
Where is all the configuration for ESLint, Jest and Babel?
In package.json
. Feel free to extract them in separate respective config files if you like.
Why are you using babel-register
instead of babel-node
?
babel-node
contains a small "trap", it loads Babel's polyfill by default. This means that if you use something that needs to be polyfilled, it'll work just fine in development (because babel-node
polyfills it automatically) but it'll break in production because it needs to be explicitely included in Babel's CLI which handles the final build.
In order to avoid such confusions, babel-register
is a more sensible approach in keeping the development and production runtimes equal. By using babel-preset-env only code that's not supported by the running environment is transpiled and any polyfills required are automatically inserted.