Home > Article > Web Front-end > How to run js files in nodejs
How to run js files in nodejs: Open the cmd command window and directly execute the "specific path of node js file name" command; you can also use the cd command in the cmd command window to locate the directory where the js file is located. , and then execute the "node js file name" command.
The operating environment of this article: Acer S40-51, nodejs 14.15.4 version, Windows10 Home Chinese version
Related recommendations: "nodejs video tutorial"
nodejs runs JavaScript script file
1. Create and write JavaScript script file
2. Open cmd command window
3. Directly execute the "node js file name specific path" command to execute the js script file
My js file is in D:\ nodejs\demo directory, so execute
node D:\nodejs\demo\hello.js
4, or first use the "cd directory path
" command to locate the directory where the js file is located, and then Execute: node fileName
command (fileName file name) to execute the corresponding js script file. Example:
node hello.js
Description:
For the js file following node, The .js suffix can be added or not
Note:
It is best not to use node.js and Chinese in the file name, and there should be no spaces in the file name
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of How to run js files in nodejs. For more information, please follow other related articles on the PHP Chinese website!