Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js | knex: command not found

Tags:

knex.js

I installed node.js on my shared hosting with Cpanel (See screenshot)

Then knex installed without any problem.

{
  "name": "cmonapp",
  "version": "1.0.0",
  "description": "APPLICATION NAME",
  "main": "start.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Meric",
  "license": "ISC",
  "dependencies": {
    "hapi-auth-jwt": "^4.0.0",
    "jsonwebtoken": "^8.2.2",
    "knex": "^0.14.6",
    "mysql": "^2.15.0"
  }
}

But when I try to run knex init command by the SSH I get an error like " -bash: knex: command not found "

Can someone help me to fix this issue?

like image 559
M.ATR Avatar asked Jun 05 '18 18:06

M.ATR


2 Answers

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 
like image 175
Subrat Avatar answered Sep 23 '22 14:09

Subrat


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.

like image 25
Emil Reña Enriquez Avatar answered Sep 23 '22 14:09

Emil Reña Enriquez