DEV Community

Cover image for Automating with Nodejs Part - 1 (Setup)
Abhishek Kale
Abhishek Kale

Posted on

Automating with Nodejs Part - 1 (Setup)

Table of Content

  1. Initializing
  2. writing the script
  3. 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

with hashbang

./filename.js
Enter fullscreen mode Exit fullscreen mode

at this point your files would look like this
added hashbang

we would add some code to test our script

const myAwesomeFunction = () => {
 console.log("Hello World")
}
Enter fullscreen mode Exit fullscreen mode

which would look like
added 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
Enter fullscreen mode Exit fullscreen mode

now you can access the script anywhere on your system

*to be continued (writing script to organize files, publishing to npm)

Top comments (0)