Personal project starter
Complete the following steps to begin a new project
# 1. First, clone to your machine
git clone https://github.com/zempo/node-starter-postgres.git my_project
# 2. Go to the project directory
cd my_project
# 3. Reset project .git history with this command
rm -rf .git && git init
# 4. Install project dependencies
npm i
# 5. Rename the example .env file, if you plan on using environmental variables in your project
mv example.env .env
Be sure to update your package.json w/ your project details!
- Add migrations then create project database
createdb -U postgres new_db
- Run migrations 1 by 1 (or all at once)
# migrate up
npm run migrate -- 1
# migrate down
npm run migrate -- 0
# migrate up, full
npm run migrate
- Seed database
psql -U postgres -d new_db -f ./seeds/seed.db_tables.sql
- Run
npm i knex
and thennpm i pg
(for postgres, in this case). - Reference the Knex Documentation for more.
- A sample db url has been added to the example env
- Getting started
const knex = require("knex");
const knexInstance = knex({
client: "pg",
connection: process.env.DB_URL,
});
console.log("connection successful");
Start the application npm start
Start nodemon for the application npm run dev
Run the tests npm test
When your new project is ready for deployment, add a new Heroku application with heroku create
. This will make a new git remote called "heroku" and you can then npm run deploy
which will push to this remote's master branch.