官术网_书友最值得收藏!

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 .
You can open files or folders directly from the command line. The period . refers to the current folder, therefore Visual Studio Code will start and open the   Hello  folder.

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).

主站蜘蛛池模板: 澳门| 黎平县| 肃南| 康平县| 保定市| 丰都县| 正宁县| 浦东新区| 日土县| 城市| 安义县| 肇庆市| 博爱县| 南充市| 嘉义市| 榆社县| 淄博市| 巫山县| 阳新县| 威海市| 万州区| 诸城市| 海安县| 孝义市| 合阳县| 威信县| 醴陵市| 安福县| 阿勒泰市| 出国| 博湖县| 泸西县| 东平县| 成安县| 曲水县| 衡山县| 湘乡市| 黎川县| 额尔古纳市| 锦州市| 仲巴县|