First Nodejs Program
This tutorial is only suitable for you already have a certain JS programming foundation or is the back-end language development Foundation.
If you are a 0 basis, it is recommended that you first learn about the front end of the old horse free video tutorial
First step: Create a project folder
First create the Demos folder. Then create the file under this folder 01_hello.js
# 以下是linux/mac下使用终端用命令行创建文件,windows下请直接用资源管理可视化鼠标操作$ mkdir demos && cd demos# 创建 01_hello.js文件$ touch 01_hello.js
Step two: Write the first program file for Nodejs
Then use the editor (recommended: Vscode or sublime) to open the file: 01_hello.js
, and add the following code:
// 以下是常规的JS语法,如果您还不熟悉js,请您移步老马的// 免费在线js全套视频教程: https://qtxh.ke.qq.com// console是控制台的意思,node把浏览器端的控制台做了迁移整合,可以直接使用。log是往控制台打印文字的方法。console.log(‘Hi, aicoder.com! Hello, world!‘);
Save the file and use node to execute the JS file.
Step three: Compile and run the JS file
Open the system's command-line tool (Mac|linux is terminal, Windows is cmd or PowerShell), and use the CD command to enter the Demos folder. Run the command to compile and execute the JS file:
# 进入demos目录$ cd demos$ node ./01_hello.jsHi, aicoder.com! Hello, world!
At this point, your first node program is already running successfully, i.e. your NODEJS environment is no longer a problem.
Old horse free Video tutorial
Back to Tutorial list home
GitHub Address: Https://github.com/malun666/aicoder_node
Node Getting Started Tutorial (4) Chapter Three: the First Nodejs program