Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!