An Express Template with PostgreSQL support.
To install Express Template type:
git clone https://github.com/erremauro/express-template <PROJECT_DIR> && cd <PROJECT_DIR> && rm -rf .git && git init && yarn install
Express Template has some example files to show you how to setup your project that you might want to remove after checking them out.
Here's a list of these files:
migrations/20180624160314_users.js
, a migration exampleapp/repos/Users.js
, a database repository exampleapp/routes/users.js
, an api route examplecore/json-response.js
, a json response utility
The application server can be run with ./bin/www [options]
. To view a
complete list of options, type:
$ ./bin/www --help
Usage: www [options]
Options:
-V, --version output the version number
-p, --port [port] Port to use (default: 3001)
-a, --address [address] Address to use (default: 0.0.0.0)
-R, --cors [headers] Enable CORS. Optionally provide cors headers separated by commas
-S, --ssl Enable https
-C, --cert [path] Path to ssl cert file (default: ./cert.pem)
-K, --key [path] Path to ssl key file (default: ./key.pem)
-g, --gzip [value] Serve gzip files when possible (default: true)
-q, --quiet Turn off logging completely
-v, --verbose Turn on server logging
-h, --help output usage information
To start the application in development mode, type:
yarn start [options]
This will start your server and watch your current working directory for changes. If any change is detected the server will be automatically restarted so you don't have to do it.
Configurations can be specified in the form of environment variables or by
using a .env
file placed in the root of your project directory. You can use
environment specific files and local files (i.e. .env.development
,
.env.test.local
). Local files have precedence over environment specific files.
Additional configurations can be found in the ./config
directory.
Option | Default | Description |
---|---|---|
HOST | localhost | Set the application address |
PORT | 3001 | Specify the default PORT |
SSL | false | Enable https |
CERT | Set the ssl certificate path | |
KEY | Set the ssl private key path |
You can customize your database configurations by editing ./knexfile.js
.
Express Template support PostgreSQL and uses knex to manage database migrations and build queries.
Express Template has a little utility to hash passwords that can be found in
core/password-hash
. Here's how to use it:
const passwordHash = require('password-hash');
const password = 'my-secret-password';
const hash = passwordHash.generate(password);
// returns true
const valid = passwordHash.verify(password, hash);
// returns false
const invalid = passwordHash.verify('wrong-password', hash);
Since it uses bcrypt you can pass
bcrypt
options when generating an hash, like the number of salt rounds:
const config = { saltRounds: 2 };
const password = passwordHash.generate('my-password', config);