Table of Content
- Initializing
- writing the script
- Install globally(on your system😜)
Description - setting up the environment to write scripts to automate tasks with nodejs and publishing to npm
part I - setup , hello world , testing locally
Initializing
prerequisites
- nodejs
- npm
create a folder for your project
cd to the folder -> do npm init
mkdir npm_script
cd ./npm_script
npm init -y
writing the script
create an index.js file(starting point of your script)
adding the hashbang!
#!/usr/bin/env node
it specifies the the environment the script will run on
without hashbang
node ./filename.js
with hashbang
./filename.js
at this point your files would look like this
we would add some code to test our script
const myAwesomeFunction = () => {
console.log("Hello World")
}
now we can test if our code runs
by just typing
./index.js
installing the script globally
npm install -g // in your script directory
now you can access the script anywhere on your system
*to be continued (writing script to organize files, publishing to npm)
Top comments (0)