How Can I Access Dom Elements Using Node Js?
Solution 1:
The error above is very explicit:
document is not defined
document is not exist in Node (e.g. server) environment, it's exist only in browser.
You will need to use separate library to parse your HTML file in order to do queries like querySelector('.container')
and etc.
Libraries to take a look (as an example):
Solution 2:
In NodeJS, the document Object doesn't exist. You can't access DOM-Nodes or anything in the DOM in NodeJS.
NodeJS is serverside Javascript.
If you want any data from the client, you have to add client-side code and send the data from the client to the server. This is done with a post-request. In the Backend, you have to setup a server with routes. To setup a server in NodeJS, use Express (frequently used). Google about it.
Solution 3:
Node.js is server side, the document doesn't exist. So the Dom doesn't exist. You need to try with client web browser side. I mean simply just create a web page document
But you can also check this answer for more information
stackoverflow.com/questions/34309557/how-to-access-dom-using-node-js
Post a Comment for "How Can I Access Dom Elements Using Node Js?"