Guest User

Untitled

a guest
Dec 9th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. - 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
  2. - Install ‘pg’ and ‘knex’ using the command ’npm install —save pg knex’
  3. - Install knex globally using nom install knex -g
  4. - initialize knex with ‘knex init’. This step creates the ./knexfile.js
  5. - Update the knexfile.js (development and production paths)
  6. - 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.
  7. - create a database from within the directory using ‘createdb <database name>’
  8. - psql <database name> to ensure it’s creation
  9. - knex migrate:make create_albums to create migrations
  10. - Edit the migrations file e.g
  11.  
  12. - exports.up = function(knex, Promise) {
  13. - return knex.schema.createTable('nba_players', function(table){
  14. - table.increments();
  15. - table.string('name');
  16. - table.string('height');
  17. - table.string('weight');
  18. - table.string('age');
  19. - })
  20. - };
  21. -
  22. - exports.down = function(knex, Promise) {
  23. - return knex.schema.dropTable('nba_players')
  24. - };
  25.  
  26. - Run the latest migration using knex migrate:latest
  27. - npm install -S dotenv (if you haven't already done this)
  28. - make a directory called db and create the knex.js file inside it. Put the following in the knex.js:
  29. - var environment = process.env.NODE_ENV || 'development';
  30. var config = require('../knexfile.js')[environment];
  31. module.exports = require('knex')(config);
  32. This initializes knex with the connection information obtained from the configuration in the knexfile.js for the current environment
  33. - Create seeds with the knex seed:make <name>. This creates a seed folder with a file called <name>.js
  34. - Edit the <name>.js file, filling in the information that is relevant to the table
  35. - run the seed, using knex seed:run
  36. - TIME FOR EXPRESS
  37. - create an index.js
  38. - npm install -S body-parser express and dotenv(if you haven’t done so already)
  39. - run the index.js file using nodemon
  40. - Copy CJ's code from the exercise :-P
  41. - open postman
Add Comment
Please, Sign In to add comment