Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
How to create my own cli using typescript and node

I want to create my own cli using typescript and node.

After building the code using tsc, I installed as a global cli using npm install -g . When running test-cli on cmd, it is expected to print "test" on console, but instead it opens a javascript file build/index.js on the editor. It seems it opens a file instead of running the file.

While checking the test-cli.cmd file in C:\Users\MyUser\AppData\Roaming\npm, I found that it is a bit different from other successful cli files.

test-cli.cmd content (not working):

...
"%dp0%\node_modules\test-cli\build\index.js"   %*
...

truffle.cmd content (working correctly):

...
IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

"%_prog%"  "%dp0%\node_modules\truffle\build\cli.bundled.js" %*
...

Definitely having a difference for specifiying node.exe to run that javascript file. How can I fix this problem?

Here's my code overview:

Source tree:

|__build
|  |__index.js
|  |__index.map.js
|__src
|  |__index.ts
|__package.json
|__tsconfig.json

index.ts just having a simple code.

// index.ts
console.log("my test cli");

Also have a simple data in package.json

// package.json
{
  "name": "test-cli",
  "version": "1.0.0",
  "main": "src/index.ts",
  "bin": {
    "test-cli": "build/index.js"
  },
  "license": "MIT",
  "scripts": {
    "build": "tsc",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "@types/node": "^17.0.22",
    "ts-node": "^10.7.0",
    "typescript": "^4.6.2"
  }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda