Hello, world!
So now, let's write our first "Hello, world!" program using Node.js
-
Create a new directory of your choice
mkdir hello-world
-
Navigate to newly created directory
cd hello-world
-
Open your preferred text editor. You can use editors like Visual Studio Code, Atom, Sublime Text, or any other editor of your choice. I'll be using vim (opens in a new tab) / neovim (opens in a new tab) through out the workshop.
If you are using
Visual Studio Code
you can run following command.code .
-
Create a new file in your text editor and save it with the name
hello-world.js
. And write the following code:console.log("Hello, world! 0/");
-
I'll create the file using the following
bash
command:echo "console.log('Hello, world! 0/');" > hello.js
-
Let's run the script
Open your terminal or command prompt. This is where you'll run your Node.js script. Type the following command and press enter:
node hello.js
Output:
$ node hello.js Hello, world! 0/
Now that you've conquered the mighty 'Hello, World!' in Node.js, you're officially a JavaScript wizard!