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

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

主站蜘蛛池模板: 石棉县| 海南省| 东海县| 景宁| 当涂县| 治县。| 玛纳斯县| 历史| 新建县| 和平区| 民权县| 五指山市| 阜新| 新绛县| 嘉祥县| 淮阳县| 宾川县| 民丰县| 宜川县| 永平县| 佳木斯市| 桑植县| 鲁山县| 涡阳县| 如皋市| 宁晋县| 玛曲县| 桑日县| 涪陵区| 胶南市| 长子县| 兴隆县| 乌兰县| 博罗县| 黑山县| 葫芦岛市| 丽江市| 宁乡县| 斗六市| 河南省| 黔西|