Marven Wilson S Donque
Marven Wilson S Donque

Reputation: 275

how am I going to test my node.js code in the browser?

newbie here.

So I have this button, when a user click on that button, a node.js fs function will execute and will create a new folder for me, that is the fs.mkdir() function,

the code is just simple, and works on the terminal too, but I do not want to work in the terminal anymore I want to test on browser, I want to bind html elements to nodejs, I am so confused right now, when I open my html file it gives me an error : "require is not define", I search and search for hours. and I realize that most of the tutorials online they test and run the code in the terminal so how does someone test on browser to know if their code works?

to summarize my problem, I just want to interact on html elements, and that elements will cause to fire a node.js functions, how do I test it in the browser?

Upvotes: 1

Views: 866

Answers (1)

jperelli
jperelli

Reputation: 7207

Node.js is used to run javascript on a node server. It runs server-side

The browser plays the role of a client

If you want to click a button in the browser and then execute a function in nodejs as a result of the click, you need to know that the architecture is a client-server

You'll need to setup a nodejs server, maybe using express.js, and then you'll need to do maybe a form in html that sends an http query from the browser to the server, so that the server executes the script you want.

client-server architecture

Upvotes: 1

Related Questions