简体   繁体   English

如何在浏览器中测试 Node.js 代码?

[英]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.

相关问题 如何转移这个 http Node.Js 在 https 上运行? - How Can I Transfer This http Node.Js to run on https? 如何在 firebase 托管(node.js)中返回 204 响应代码 - how to return a 204 response code in firebase hosting (node.js) 如何在PHP文件/脚本中使用Node.js代码 - How to use node.js code inside php file/script 如何在 Travis CI 的 PHP 容器上安装特定的 node.js 版本? - How can I install a specific node.js version on a PHP container on Travis CI? 如何互连Node.js应用程序服务器和LAMP堆栈? - How can I interconnect a Node.js Application server and a LAMP stack? 如何使用Node.js或PHP实时侦听MySQL数据库更改 - How can i listen MySQL database changes in real time with Node.js or PHP 从 PHP exec() 调用 Node.js 脚本时如何传递参数? - How can I pass parameters when calling a Node.js script from PHP exec()? 如何使用 Proxy 在 Node.js 中模拟 PHP 的 __callStatic 属性? - How I can simulate the __callStatic property of PHP in Node.js using Proxy? 如何将PHP用户详细信息(会话)解析到Node.js服务器? - How can I parse PHP user details (session) to Node.js server? 如何在带有Node.js / Socket.IO的PHP中使用popen? - How can I use popen in PHP with Node.js/Socket.IO?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM