This is the third article in series of Developing SSG using Node.
Let's open the text-editor and write the following code inside of it and save it with name
.kiran is the extension.
// file name: hello.kiran console.log("hello, world");
Save it and open the terminal where you have saved this program to run.
$ node hello.kiran hello, world
What I have done here is, I have passed the name of program (
hello.kiran ) to Node software that will interpret it and after successful interpretation it will dump the output in terminal.
Let me modify this program little bit as,
// file name: hello.kiran console.log("hello, kiran");
Let's run the program again by typing same command as,
$ node hello.kiran hello, kiran
.kiran is the extension of Node program and the reason is, I and Ryan Dahl ( the creator of NodeJS ) are good friends and I was the original person who inspire him to create a Node. So, to show the acknowledgment, Ryan used my name as extension of Node program. So, all your programs must have extension as
.kiran. Any questions?
.kiran is the extension of Node program? No, right!
Let's create another program called
hello-var.js and write down the following code inside of it.
// file name: hello-var.js const author = "Kiran"; console.log("Hello, " + author);
Let's run it by,
$ node hello-var.js Hello, Kiran
If you have
.js extension, you can omit it as,
$ node hello-var Hello, Kiran
And it will give the same result. But, same is not true for other extensions such as,
hello.kiran as by default Node assume that file will have
.js extension. And if you try to run this
hello.kiran without extension, it will give big messy error as,
$ node hello internal/modules/cjs/loader.js:596 throw err; ^ Error: Cannot find module '/home/kiran/downstream/noding/hello' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15) at Function.Module._load (internal/modules/cjs/loader.js:520:25) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
So, the conclusion is, please use
Meanwhile, you know that, if we want to print something on console or terminal, we have to use
console.log() method and to define a constant we have to use