node.js | knex: command not found
knex
binary will be installed in the node_modules/.bin
folder.
If you are using [email protected]
and above, use npx
to access your local dependencies like:
➜ npx knex --version
Knex CLI version: 0.15.0
Local Knex version: 0.15.0
If npx
is not available,
➜ $(npm bin)/knex --version
Knex CLI version: 0.15.0
Local Knex version: 0.15.0
Needless to say knex init
command would work in both the options
➜ npx knex init
Created ./knexfile.js
either install knex globally
npm install -g knex
or
use npx knex
this will read to your node_modules directory and run the bin/knex executable.
You installed it locally to your NodeJS project.
Sou you can const knex = require('knex')
.
But you can't knex -v
.
To install it globally run npm i -g knex