Node.js and HTML
NickName:DCS Ask DateTime:2018-07-20T06:41:56

Node.js and HTML

I am new to and I'm trying to run a script that uses Node.js' require() when a html button is clicked but it simply says "require" is not recognized (which makes sense).

So how exactly can I activate my node.js script when the HTML button is clicked in this case?

Thank you.

Copyright Notice:Content Author:「DCS」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/51432657/node-js-and-html

Answers
Dupocas 2018-07-19T22:48:06

You could use some library like express to handle requests and responses easely. In your case when the button is clicked a request is done to a server thats running node, the server handles the request and then sends back a response.\n\nSee more in Anatomy of an HTTP Transaction in Node's oficial docs.",


Ashish Dommety 2018-07-19T22:52:45

The purpose of Node.js is to write server-side code in Javascript. This means that you can't use this functionality in the browser.\n\nHowever, to accomplish what you were asking, you can use a framework like Express.js (a node package with Node.js)\n\nThen, you need to set up an ajax request from the front-end that communicates with your server. You can launch an asynchronous call once your button is clicked, which can be received on the back-end using Express.js",


More about “Node.js and HTML” related questions

Node.js and HTML

I am new to node.js and I'm trying to run a script that uses Node.js' require() when a html button is clicked but it simply says "require" is not recognized (which makes sense). So how exactly ca...

Show Detail

Using node.js in html

I already know how to load and host html using node.js. I created a website (only html and css, including some Javascript for frontend) that's frontend is fully finished. I won't be adding any other

Show Detail

node.js websocket server to html

I was wondering if you could help me with a conundrum. I'm new to node.js and would appreciate some help. I have a simple html (client) page using jquery and socket.io.js a external server. the cl...

Show Detail

html and node.js script on the same heroku instance

I'm trying to get something very simple to work with node.js and im kind of stuck at the moment . Hoping someone could help me out with this problem.. Im trying a very simple node.js application..

Show Detail

Connecting an HTML running Javascript to Node.js

for my group university project we were assigned to create a chat bot. We created it in an HTML file that has attached javascript scripts in order to change the HTML to add and get text from the us...

Show Detail

jQuery in HTML with node.js as backend

I'm new to jQuery and node.js and this question has been bugging me for a couple of hours, I've searched stackoverflow and googled but couldn't find a solution. I'm testing this "hello world" exam...

Show Detail

Node.js hide html name on url

I have Node.js application can I hide the html file name from browser url to protect all html files means if Node.js using port 9090 then the url browser will be http://<ip address>:9090/ ...

Show Detail

Node.js Parsing HTML

OK, I am creating a node.js module that will be a simple and fast HTML parser. Basically I want to be able to parse an HTML file for a certain tag, for example: <html> <head> &lt...

Show Detail

Using node.js to create an html file

I'm fairly new to using none basic code (I.E. jquery, node.js,and the like) And I couldn't find a way to create and save an html document on the server. I've been told that node.js has no DOM

Show Detail

Node.js HTTP client with HTML

I have a simple web server on my ESP8266 and I'm able to communicate with it with my Node.js HTTP client and sending commands on terminal only. I want to connect an HTML webpage to my Node.js HTTP ...

Show Detail