After entering the factory, found that a lot of big bosses have their own scaffolding, attracted countless small white envy of the eyes
As a programmer with dreams, how can not have their own exclusive scaffolding, open!!
Me: the man who has his own scaffolding is the most handsome programmer in the world
Girlfriend: Speechless ing
Me: First of all, let’s build a folder, called cliDemo, and then enter the folder, use the command line
NPM init -y // Use default SettingsCopy the code
A package.json file comes out from the folder
Add bin to package.json
Girlfriend: What’s bin for
Me: It is to write an internal command, such as I wrote ‘ws’, the right side is the command corresponding to the file to execute
So we create a bin folder in the root directory, and write main.js to the folder, in main.js
#! /usr/bin/env nodeCopy the code
#! /usr/bin/env this line of code is used when the system is running on this line to look up the node configuration and call the corresponding interpreter to run the subsequent node programCopy the code
Then write to main.js
console.log('hello ws');
Copy the code
The key to asynchrony comes from typing on the command line
npm link
Copy the code
Girlfriend: What is NPM link
Me: He just installed our WS command globally so that we could use it elsewhere and execute it on the command line
ws
Copy the code
Our console.log statement comes out, isn’t it amazing
If you have any problems with the code above, please leave a comment in the comments section. If it is useful, please give a thumbs up
To be continued
reference
How to build your own scaffolding