简体   繁体   中英

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. In PHP all I ever needed was an Apache as localhost and MySQL.

But when I use Node.js, what do I need ? 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 is a runtime for JavaScript code that is specifically not run in the browser. 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 myFile.js

This will execute whatever is in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM