Node.js ECMAScript class-based module and command-line interface (CLI) template starting point
- Install nvm
- Download the zip
- Decompress anywhere on your computer and
cd
into the root - Install dependencies using
npm i
- Execute
npm start
to see the output
- Create a development-only/temporary globally-installed symbolic link
npm link
(usenpm unlink
to uninstall) - Execute
nmcli
to see the output
Using this repository as a starting point …
echo "# My cool node thingy!" > README.md
Edit package.json
Add a name
:
"name": "changeme"
… and provide your own CLI command name:
"bin": {
"changeme": "app/cli.js"
},
Enter values for all other keys (only name
and version
fields are required).
The module’s entrypoint is app/index.js
. Use this as a starting point, or feel free to wipe everything and start fresh … The existing code is for demo purposes only.
I wanted to have the option of passing params via import
AND method invocation:
const genericModule = GenericModule({
red: "black",
green: "purple",
})
// ... and later:
let result = await genericModule({
orange: "blue",
}).run()
Alternatively:
const genericModule = GenericModule({
// Options can be passed here:
red: 'black',
green: 'purple',
})();
// ... and later:
let result = await genericModule.run();
Set your npm author info:
npm set init.author.name 'Your Name'
npm set init.author.email 'you@example.com'
npm set init.author.url 'http://yourblog.com'
npm adduser
Next, bump version number in package.json
and publish on npm:
npm publish
Copyright © 2023 Michael Hulse
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.