What is npx and how to get it?

When trying to create a new rails app, things fail with this error:

Errno::ENOENT: No such file or directory - npx

The docs say this is needed, but don’t give information about how or where to get it. It is apparently not even supported on Unix:

$ find /usr/ports -type d -name "*npx*"
$

The code also doesn’t give much clue: that npx is called unconditionally and without actually using it.

I got to this when I tried to create with esbuild. Before that I tried to use the default importmaps, but that gives an error in the browser that it doesn’t understand mimetype application/javascript+ruby. Apparently importmaps expects the browser to compute the erb code in my JS files. :rofl:

npx is part of npm/node. you should install nodejs

Ah, thanks. Actually I have it installed, but…

$ pkg list node16 | grep npx
/usr/local/lib/node_modules/corepack/dist/npx.js
/usr/local/lib/node_modules/corepack/dist/pnpx.js
/usr/local/lib/node_modules/corepack/shims/nodewin/npx
/usr/local/lib/node_modules/corepack/shims/nodewin/npx.cmd
/usr/local/lib/node_modules/corepack/shims/nodewin/npx.ps1
/usr/local/lib/node_modules/corepack/shims/nodewin/pnpx
/usr/local/lib/node_modules/corepack/shims/nodewin/pnpx.cmd
/usr/local/lib/node_modules/corepack/shims/nodewin/pnpx.ps1
/usr/local/lib/node_modules/corepack/shims/npx
/usr/local/lib/node_modules/corepack/shims/npx.cmd
/usr/local/lib/node_modules/corepack/shims/npx.ps1
/usr/local/lib/node_modules/corepack/shims/pnpx
/usr/local/lib/node_modules/corepack/shims/pnpx.cmd
/usr/local/lib/node_modules/corepack/shims/pnpx.ps1

… never looked into these.

Hello Everyone, npx is a package runner tool that comes with Node.js. It allows you to run executables from npm packages without having to globally install them first.

It is used to run the executables of packages that are not globally installed on your system. This allows you to run a package’s executable without having to install it globally, which can be useful in situations where you want to use a specific version of a package for a single project, or if you’re working on multiple projects with different package requirements.

npx is included with Node.js, so you don’t need to install it separately. If you have Node.js installed on your computer, then you already have npx. You can check if you have it by running npx -v on your command line. If you have it installed, it will return the version number.

You can use npx to run an executable from an npm package by specifying the package name followed by the command you want to run, for example npx <package-name> <command>.

For example, if you wanted to run the create-react-app package’s executable, you could run npx create-react-app my-app in your command line, this will create a new React project in a directory called my-app. If you are not satisfied from this comment then you can get this help for more deeply understanding.