Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### KNEXFILE:
- module.exports = {
- development: {
- client: process.env.DB_CLIENT,
- connection: process.env.DB_CONNECTION,
- migrations: {
- directory: process.env.DB_MIGRATION_DIR,
- },
- seeds: {
- directory: process.env.DB_SEEDS_DIR
- },
- useNullAsDefault: true
- },
- production: {
- client: process.env.DB_CLIENT,
- connection: process.env.DB_CONNECTION,
- migrations: {
- directory: process.env.DB_MIGRATION_DIR,
- },
- seeds: {
- directory: process.env.DB_SEEDS_DIR
- },
- useNullAsDefault: true
- }
- };
- ######### demonstrating environment properties are setup--
- #checking .env file for properties:
- $ node
- > process.env.DB_CLIENT
- 'postgresql'
- > const dotenv = require('dotenv').config();
- undefined
- > dotenv
- { parsed:
- { NODE_ENV: 'production',
- DB_CLIENT: 'postgresql',
- DB_CONNECTION: 'postgres://pat:secret@localhost:5432/timetracker',
- DB_MIGRATION_DIR: './db/migrations',
- DB_SEEDS_DIR: './db/seeds' } }
- #### problem code:
- const dotenv = require('dotenv').config();
- const knex = require('knex');
- const environment = process.env.NODE_ENV;
- const knex_config = require('./knexfile')[environment];
- const database = require('knex')(knex_config);
- # CAUSES ERROR:
- TypeError: Cannot read property 'client' of undefined
- at Knex (/home/pat/apps/timetracker/node_modules/knex/lib/index.js:49:41)
- FROM KNEX SOURCE FILE FILE -- ASTERISKS == LINE 49
- // The client names we'll allow in the `{name: lib}` pairing.
- var aliases = {
- 'mariadb': 'maria',
- 'mariasql': 'maria',
- 'pg': 'postgres',
- 'postgresql': 'postgres',
- 'sqlite': 'sqlite3'
- };
- function Knex(config) {
- if (typeof config === 'string') {
- return new Knex((0, _assign3.default)((0, _parseConnection2.default)(config), arguments[2]));
- }
- var Dialect = void 0;
- if (arguments.length === 0 || !config.client && !config.dialect) { // ************* LINE 49 *************
- Dialect = _client2.default;
- } else if (typeof config.client === 'function' && config.client.prototype instanceof _client2.default) {
- Dialect = config.client;
- } else {
- var clientName = config.client || config.dialect;
- Dialect = require('./dialects/' + (aliases[clientName] || clientName) + '/index.js');
- }
- if (typeof config.connection === 'string') {
- config = (0, _assign3.default)({}, config, { connection: (0, _parseConnection2.default)(config.connection).connection });
- }
- return (0, _makeKnex2.default)(new Dialect(config));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement