Giter Club home page Giter Club logo

todo-app's Introduction

Todo App

Todo application using Node.js, Express, postrges, Knex.js, and handlebars

Getting Started

Prerequisites

  1. Clone Repository:

     $ git clone https://github.com/egarcia410/todo-app.git
    
  2. Change Directory:

     $ cd todo-app
    
  3. Install Dependencies:

     $ npm install
    
  4. Enter PostgreSQL shell

     $ psql
    
  5. Inside PostgreSQL shell, create a database called todos

     =# CREATE DATABASE todos
    
  6. Update your database

     $ knex migrate:latest
    

    A table will be created in your database called todos

  7. Run Program:

     $ nodemon server.js
    

Setting up database with Knex.js

Prerequisites

  1. Enter PostgreSQL shell

     $ psql
    
  2. Inside PostgreSQL shell, create a database

     =# CREATE DATABASE <NAME_OF_DATABASE>
    
  3. Install Knex.js and PostgreSQL driver inside working directory

     $ npm install --save knex pg
    
  4. Create a new knexfile

     $ knex init
    

    A knexfile.js file will be created

  5. Configure knexfile.js with appropriate database client

    Example using PostgreSQL configuration:

     module.exports = {
         development: {
             client: 'pg',
             connection: 'postgres://localhost/<NAME_OF_DATABASE>'
         },
         production: {
             client: 'postgresql',
             connection: process.env.DATABASE_URL
         }
     };
    
  6. Create a new migration file

     $ knex migrate:make <MIGRATION_NAME>
    

    A migrations folder will be created

  7. Configure migrations file with a createTable and dropTable

  8. Update your database

     $ knex migrate:latest
    

    A table will be created in your database

  9. Create db folder

     $ mkdir db
    
  10. Create knex.js file inside db folder

    $ touch db/knex.js
    
  11. Insert into knex.js:

    let environment = process.env.NODE_ENV || 'development';
    let config = require('../knexfile.js')[environment];
    module.exports = require('knex')(config);
    

    acquires database client and connection

  12. Require the exported module in file where queries will be made

    Example:

    const knex = require('./db/knex');
    

todo-app's People

Contributors

egarcia410 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.