

Step 3 - Receiving User Input via Command Line ArgumentsĮvery time you run the Node.js “Hello, World!” program, it produces the same output. Having confirmed that the program works, let’s make it more interactive. The string "Hello World" was passed as an argument to the log function.Īlthough quotation marks are necessary in the code to indicate that the text is a string, they are not printed to the screen. The Node.js interpreter read the file and executed console.log("Hello World") by calling the log method of the global console object. With the text editor opened, enter the following code:

To write a “Hello, World!” program, open up a command line text editor such as nano and create a new file: A basic knowledge of JavaScript, which you can find here: How To Code in JavaScript.To install this on macOS or Ubuntu 18.04, follow the steps in How to Install Node.js and Create a Local Development Environment on macOS or the “Installing Using a PPA” section of How To Install Node.js on Ubuntu 18.04. This tutorial uses Node.js version 10.16.0. Node.js installed on your development machine.To complete this tutorial, you will need: To do this, you’ll learn how to output strings to the console, receive input from the user, and access environment variables. You’ll be introduced to a few Node-specific concepts and build your way up to create a program that helps users inspect environment variables on their system. In this tutorial you’ll create your first program with the Node.js runtime. Real-time applications, like video streaming, or applications that continuously send and receive data, can run more efficiently when written in Node.js. Using JavaScript throughout your entire stack can help reduce time for context switching, and libraries are more easily shared between your back-end server and front-end projects.Īlso, thanks to its support for asynchronous execution, Node.js excels at I/O-intensive tasks, which is what makes it so suitable for the web. Learning Node.js will allow you to write your front-end code and your back-end code in the same language. The Node runtime is commonly used to create command line tools and web servers. Node.js is a popular open-source runtime environment that can execute JavaScript outside of the browser using the V8 JavaScript engine, which is the same engine used to power the Google Chrome web browser’s JavaScript execution. The author selected the Open Internet/Free Speech Fund to receive a donation as part of the Write for DOnations program.
