I'm learning how to create a Command-Line Interface Applications (CLI) tool
and performed the following steps:
I created a folder and inside it in the terminal rodei
npm init--yes
In this folder, I created the package.json
in this folder. I created a bin folder and inside it an index.js file
After that I have arranged package.json so that it makes index.js as an executable with the command forecast
{
"name": "tableless-cli",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"bin": {
"forecast": "./bin/index.js"
}
}
I put this code in index.js
#! /usr/bin/env node
var https = require('https')
var arguments = process.argv.splice(2, process.argv.length -1).join(' ')
console.log(arguments);
In the terminal I ran:
npm link
forecast
to turn into executable and forecast was what I defined in package.json
I opened the cmd folder in the place where it has the package.json and rode error and test test. says forecast is an invalid command, where am I wrong?