Issue with logging messages using console.log in Knex migration script

My concern: I am facing an issue where the

console.log('tableNobject: ', tableNobject)
does not get logged in my knex migration script.
I have attempted the following code snippets:

//solution A
export async function up(knex: Knex) {
  const tableAobject = await knex.select('*').from('tableAobject');
  console.log('tableAobject: ', tableAobject);
}

//solution B
export async function up(knex: Knex) {
  await knex.select('*').from('tableBobject').then((tableBobject) => {
    console.log('tableBobject: ', tableBobject);
  });
}

However, the output on my terminal is as follows:

Migration Starting ...
Migrated
Migration Done.

These logs are from our migration script where we invoke database.migrate.latest()

The expected terminal output for the provided code should be something like this:

Migration Starting ...
tableNobject: [
  {
    id: 'randomId'
    someData: 'someDataString'
    ...
  },
  ...
]
Migrated
Migration Done.

I am aware that logging tables fetched through knex is feasible because when I ran a test script outside the migration flow, I was able to log the table data without any issues.

I have also experimented with different settings additions such as:

const configA = {
  ...
  debug: true,
}

const configB = {
  ...
  log: {
    warn(message) {
      console.log(message)
    },
    error(message) {
      console.log(message)
    },
    deprecate(message) {
      console.log(message)
    },
    debug(message) {
      console.log(message)
    },
  }
}

const configC = {
  ...
  debug: true,
  log: {
    warn(message) {
      console.log(message)
    },
    error(message) {
      console.log(message)
    },
    deprecate(message) {
      console.log(message)
    },
    debug(message) {
      console.log(message)
    },
  }
};

Despite trying out the above settings variations, they do not provide the desired logging output in the terminal.

Here are the base settings (not sure if these add any value):

const config = {
  client: 'postgresql',
  connection: {
    host: '127.0.0.1',
    port: '5432',
    database: 'projectName_develop',
    user: 'user',
    password: 'dev',
  },
  pool: {
    min: 2,
    max: 10,
  },
  migrations: {
    tableName: 'knex_migrations',
    directory: path.join(__dirname, 'migrations'),
  },
  seeds: {
    directory: path.join(__dirname, 'seeds'),
  },
  asyncStackTraces: true,
};

Answer №1

After scratching my head for a bit, I finally realized why my console.log wasn't working - turns out the migrations were TypeScript files.
I completely forgot to execute the npm run build-ts-backed:watch command.

It's funny how sometimes the solution is much simpler than the problem itself. Always remember to compile your TypeScript code before testing it!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing ChartJS to convert a chart into a Base64 image within a Vue environment

I am currently utilizing the PrimeVue chart component, which is built on top of ChartJS. The configuration is very similar. The documentation indicates that I need to instantiate a new Chart() and then call toBase64Image(); My main query is, how do I ac ...

Highlighting JavaScript code with React Syntax Highlighter exclusively

I've been struggling to highlight Ruby code, but it seems like no matter what I do, it keeps highlighting JavaScript instead. It's frustrating because I can't seem to get it right. import React from "react"; import atom from "node_module ...

Having trouble with the initial tap not being recognized on your mobile browser?

When using mobile web browsers (specifically chrome and firefox on iOS), I am experiencing an issue where the hamburger menu does not trigger when tapped for the first time. For a simplified version of the HTML/CSS/JS code, you can check it out at: https ...

What steps should I follow to change the appearance of this object to match this?

Attempting to modify the value of an object nested within an array, which is in another object. The nesting might be a bit complex... Here's how it currently looks { household and furniture: [{…}, {…}], school stuffs: [{…}, {…}] } M ...

Guide on transforming a select dropdown into a ul dropdown

I am attempting to transform my select dropdown menu into an unordered list (ul) in order to create a bootstrap button that will display the ul, allowing the list items to function as options. <select id="sortField" onchange="refreshPage('{$pageBa ...

Laravel's routing system may cause complications when trying to send data via jQuery AJAX post requests

My current challenge involves passing an ID to a PHP script through AJAX. Previously, everything was working perfectly with the code snippet below: var baseURL = '/W4W/public/'; function voteUp(){ var snippetID = document.getElementById(&ap ...

Firefox not rendering responsive YouTube embed properly

This method of embedding seems to be functioning well on all browsers except for Firefox; I took advantage of a free trial at crossbrowsertesting.com to verify. I’m not using a direct iFrame embed, and all the solutions I’ve come across are related to ...

Is it possible to compare two charts in Chart.js in a way that avoids the issue of small values appearing as large as big values?

I am currently working on a production tracking page that features multiple charts. I want to avoid inconsistencies in tracking at first glance. Is there a way to achieve this using chart.js? If not, what would be the best approach to address this issue? ...

Are toggle functionalities triggered when an element is clicked?

How come the span triggers functions a and b when first clicked, is there a way to set it up so that it calls function a on the first click and then function b on the second click? function a(id) { $.post("url.php", {'id':id}, function() { ...

Guide: Generating a dynamic textbox on click event without needing to reload the page

I need assistance with the following form:- <form action=""> <table border="0"> <td colspan="2" class="instruction">Please select an option to search.</td> </table> <table> <tr> ...

Create a dynamically updating list using React's TypeScript rendering at regular intervals

My goal is to create a game where objects fall from the top of the screen, and when clicked, they disappear and increase the score. However, I am facing an issue where the items are not visible on the screen. I have implemented the use of setInterval to d ...

Navigating through Node and Express on Azure App Service

I'm facing an issue that I am not sure if it is related to Node or Azure App Service, so here's the situation: In my Node/Express app, I have defined two routes: router.get("/users", checkAuthHeader, userController.getUsers); router.po ...

The power of absolute paths in React Native 0.72 with TypeScript

Hi everyone! I'm currently having some difficulty setting absolute paths in react native. I tried using babel-plugin-module-resolver, as well as configuring 'tsconfig.json' and 'babel.config.js' as shown below. Interestingly, VS Co ...

The controller and node js request associated are invisible to my HTML page

Here is my HTML code. I have just created a unique controller for a specific part of the code. <div class="mdl-grid" ng-controller="ValueController"> <div class="mdl-card mdl-shadow--4dp mdl-cell--12-col"> <div class ...

Capturing an error within an asynchronous callback function

I am utilizing a callback function to asynchronously set some IPs in a Redis database. My goal is to catch any errors that occur and pass them to my error handling middleware in Express. To purposely create an error, I have generated one within the selec ...

Unable to execute commitlint in husky along with a different custom command

Is it possible to set up two precommit hooks with husky? Specifically, I want to integrate commitlint along with a custom script specified in my package.json. After installing husky and creating a pre-commit script in the .husky folder, here is what I have ...

The AMP HTML file is unable to load due to the robots.txt file on https://cdn.ampproject.org restricting access

I've been trying to fetch and render my AMP HTML files individually, but they all seem to be encountering the same issue. According to the Search Console report, it says "Googlebot was unable to access all resources for this page. Here's a list: ...

Exploring the bounds of self-invocation functions in JavaScript

Have you ever wondered why self-invocation functions inside another function in JavaScript don't inherit the scope of the outer function? var prop = "global"; var hash = { prop: "hash prop", foo: function(){ console.log(this.prop); ...

Is there a way in jqGrid to invoke a function once the subGridRowCollapsed operation finishes?

I'm currently working with jqGrid's subgrids and I need a solution for invoking a specific method after collapsing a subgrid. Currently, my implementation is as follows: subGridRowCollapsed: function (subgrid_id, row_id) { adjust_slider_posi ...

The development server fails to respond when initializing a new project following the NextJs documentation for an empty project

After consulting the NextJs framework documentation, I meticulously followed the setup instructions to initialize an empty project : mkdir hello-next cd hello-next npm init -y npm install --save react react-dom next mkdir pages Subsequently, I included t ...