Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - npm init-y to create the package.json. Use `npm install <pkg> --save` afterwards to install a package and save it as a dependency in the package.json file
- - Install ‘pg’ and ‘knex’ using the command ’npm install —save pg knex’
- - Install knex globally using nom install knex -g
- - initialize knex with ‘knex init’. This step creates the ./knexfile.js
- - Update the knexfile.js (development and production paths)
- - Migrations allow for you to define sets of schema changes that modify the database schema. The migration cli is bundled with the knex global install.
- - create a database from within the directory using ‘createdb <database name>’
- - psql <database name> to ensure it’s creation
- - knex migrate:make create_albums to create migrations
- - Edit the migrations file e.g
- - exports.up = function(knex, Promise) {
- - return knex.schema.createTable('nba_players', function(table){
- - table.increments();
- - table.string('name');
- - table.string('height');
- - table.string('weight');
- - table.string('age');
- - })
- - };
- -
- - exports.down = function(knex, Promise) {
- - return knex.schema.dropTable('nba_players')
- - };
- - Run the latest migration using knex migrate:latest
- - npm install -S dotenv (if you haven't already done this)
- - make a directory called db and create the knex.js file inside it. Put the following in the knex.js:
- - var environment = process.env.NODE_ENV || 'development';
- var config = require('../knexfile.js')[environment];
- module.exports = require('knex')(config);
- This initializes knex with the connection information obtained from the configuration in the knexfile.js for the current environment
- - Create seeds with the knex seed:make <name>. This creates a seed folder with a file called <name>.js
- - Edit the <name>.js file, filling in the information that is relevant to the table
- - run the seed, using knex seed:run
- - TIME FOR EXPRESS
- - create an index.js
- - npm install -S body-parser express and dotenv(if you haven’t done so already)
- - run the index.js file using nodemon
- - Copy CJ's code from the exercise :-P
- - open postman
Add Comment
Please, Sign In to add comment