Installing knex itself:
npm install knex --save
Please note that we did not install knex globally, so now we will add shortcuts for its main commands to package.json. "package.json" should now contain "scripts" section which look like this:
"scripts": {
    "migrations-run": "cd ./database && ../node_modules/knex/bin/cli.js migrate:latest",
    "migrations-rollback": "cd ./database && ../node_modules/knex/bin/cli.js migrate:rollback"
}
To see the full list of commands available for knex execute following command in your project's root dir: ./node_modules/knex/bin/cli.js

According to our "scripts" section in the package.json, we can see that we are going to keep our migrations in "database" directory. This means that we need to locate knex configuration in file "database/knexfile.js" This file contents will look like this:
module.exports = {

    development: {
        client: 'mysql',
        connection: {
            database: 'test',
            user: 'root',
            password: '',
            host: 'localhost'
        },
        migrations: {
            tableName: 'knex_migrations'
        }
    },
    production: {
        client: 'mysql',
        connection: {
            database: 'prod_test',
            user: 'prod_user',
            password: '',
            host: 'localhost'
        },
        pool: {
            min: 2,
            max: 10
        },
        migrations: {
            tableName: 'knex_migrations'
        }
    }
};
Now let's create a dir for migrations files itself:
mkdir ./database/migrations
And now let's generate our first migration file using knex cli:
cd ./database && ../node_modules/knex/bin/cli.js migrate:make users_table
This command will generate a new file with name like "xxxxxxxx_users_table.js" and place it to "database/migrations" folder.

Now let's add some content to our first migration:
exports.up = function(knex, Promise) {
    return knex.schema.createTable('user', function(table) {
    table.charset('utf8');
    table.collate('utf8_general_ci');
    table.increments('user_id').primary();
    table.string('email', 150).nullable(false);
    table.string('password', 255).nullable(false);
    table.timestamps();
  });
};

exports.down = function(knex, Promise) {
    return knex.schema.dropTable('user');
};
And now we can check our first migration by going to the project root folder and running command "npm run migrations-run".

I personally prefer knex migrations over "node-migrate" or "node-db-migrate" packages because it has a complete documentation, and it is also a general purpose query builder library which can be useful for the project in further.