- Hands-On Serverless Computing
- Kuldeep Chowhan
- 328字
- 2021-08-05 10:35:39
Node.js tutorial in VS Code
In this section, we will look into how we can write Node.js code in Visual Studio Code. We will also be looking at how to run Node.js code. Visual Studio Code has out-of- the-box support for the Node.js JavaScript language and also has support for Node.js debugging. To demonstrate this, we will create a file, Node.js, which will print Hello Reader!:
Hello Reader!
Let's get started by creating a Node.js file to print Hello Reader!.
Create an empty folder called scratch, navigate into it, and open it with Visual Studio Code:
mkdir scratch
cd scratch
code .
From the File Explorer toolbar, press the New File button:

Name the file hello-readers.js :

Set the extension of the file to .js and, by using the .js file extension, Visual Studio Code will interpret this file as JavaScript and will evaluate the contents with the JavaScript language service.
Create a simple string variable in hello-readers.js and print the contents of the string to the console:
const message = 'Hello Readers!';
console.log(message);
If you take a close look, when you typed console. in Visual Studio Code IntelliSense, (https://code.visualstudio.com/docs/editor/intellisense), the console object was automatically presented to you with one of the options being .log. When editing JavaScript files, Visual Studio Code will automatically provide you with IntelliSense for the DOM:

Also notice that Visual Studio Code knows that message is a string based on the initialization to 'Hello Readers!'. If you type message, you'll see IntelliSense showing all of the string functions available on message:

After experimenting with IntelliSense, revert any extra changes from the source code example above and save the file (cmd + S).