Invalid call to knex.js db

I am learning node.js and have come across knex.js and bookshelf.js for interacting with various databases. I am trying to run a simple knex program, but somehow the program does not exit. The following is the program:

'use strict'; console.log('Getting knex'); var knex = require('./knex')({ client: 'mysql', connection: { host: '127.0.0.1', user: 'shankhoneer', password: 'password', database: 'knex_test' } }); debugger; console.log('got knex'); knex.schema.createTable('users', function(table) { console.log('creating tables'); table.increments('id'); table.string('user_name'); }).then (function(msg){ console.log('Completed creation'); console.log(msg); return {inserted: true}; }); 

I tried debugging and found that knex uses bluebird promises. Is my problem due to an incomplete way out of a promise? Thanks

+6
source share
1 answer

This is because the database connection is still open. Add the following code after the last .then( ... ) and it will shut down (thus exiting the process):

 .finally(function() { knex.destroy(); }) 
+9
source

Source: https://habr.com/ru/post/983350/


All Articles