[英]How can I test Node.js code to the browser?
I used to use PHP in my projects and MySQL of course, but I'm starting a course to Node.js right now and I really don't understand how it works.我曾经在我的项目和 MySQL 中使用过 PHP,但我现在开始学习 Node.js,我真的不明白它是如何工作的。 In PHP all I ever needed was an Apache as localhost and MySQL.
在 PHP 中,我所需要的只是一个 Apache 作为本地主机和 MySQL。
But when I use Node.js, what do I need ?但是当我使用 Node.js 时,我需要什么? The main question is how and where I can implement and write Node.js code and how I test it on the browser like I used to do in PHP?
主要问题是如何以及在何处实现和编写 Node.js 代码,以及如何像以前在 PHP 中那样在浏览器上测试它?
Node.js is a runtime for JavaScript code that is specifically not run in the browser. Node.js 是 JavaScript 代码的运行时,专门不在浏览器中运行。 To execute JavaScript in Node.js, you simply run Node.js from the command line and supply your JavaScript source file as an argument.
要在 Node.js 中执行 JavaScript,您只需从命令行运行 Node.js 并提供 JavaScript 源文件作为参数。
node myFile.js
This will execute whatever is in myFile.js
.这将执行
myFile.js
任何内容。 This file could look like the following:该文件可能如下所示:
let myVar = 1;
for (myVar; myVar < 5; myVar++) {
console.log(myVar);
}
This would print the following to the command line, when run:运行时,这会将以下内容打印到命令行:
1234
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.