We all know that Gists are a very good way to share code templates or embed code in our articles or website.
If you don't know about Gists see this
Apart from that, we can use Gists to create smaller and single-file scripts.
To add more power, with the help of Npx, consumers can run these scripts from their command line.
Let's consider a small example. Below are the Index.js and package.json files from my public gist.
The Link to the above gist is here
Make sure you have npm installed on your machine. If not installed refer to this
Now open your command line/terminal, copy the below command, and paste
ย
npx https://gist.github.com/umamahesh51/797c37a1d51a1affdee01a96c74ebe33
Hit enter, You will see the ok to proceed question Like below.
type y
You will see the output like this.
in the above example we have "bin":"./index.js" so the index.js file will be executed.
It is the same as using the command
node index.js
But instead of downloading the repository and then run the command, we are executing the package directly.
It will be applicable to GitHub repositories as well.
Try the npx with this repo
Use below command
npx https://github.com/umamahesh51/TestGist
A famous and complex example of this case is create-react-app
How we can utilize this feature of gists?
We can provide scripts that will do some useful things and share them with others, instead of building them and giving executable files, we can just provide a link to gist.
Repositories will be useful if we have a complex task like create-react-app. Where as gists are a way to provide small scripts.
My favorite useful gist which we can run using npx is
Export @code Extensions to a Markdown List
Try it and see.
That's all I have. Let me know if you have seen some interesting usages of Gists.
Top comments (1)
See me writing code for 365 days
github.com/umamahesh51/365DaysOfCo...