I'm kind of new to node.js and Javascript so forgive me if the question is poorly worded.
I'm using cheeriojs to scrape data from a site. I'm running the js file that scrapes the data in the command line and it outputs the data I want, but I want to be able to have access to this data on a webpage, where I can put it into a table. (or anything else I want for that matter). How exactly do I do this?
Thank you
Learn how to use express.
Serve the page to a browser, by reading the file and serving it with an express endpoint, or to curl or something. ie curl localhost:8080/your-endpoint
Using the browser manipulate the page inside of the browsers dev tools.
Figure out how to get the current DOM as an html string.
Figure out how to use the fetch API inside of a browser such as fetch(url, {method: 'POST'}).then(...)
After manipulating the DOM with the browsers dev tools.
POST the results back to express on the nodejs server.
Save the req.body or req.data or req.params to a file.
Side notes:
- figure out what a callback is, figure out how promises work
- do some research on express middleware
- look into setInterval, setTimeout
Related:
Node.js quick file server (static files over HTTP)
How do I get HTML corresponding to current DOM tree?
fetch(), how do you make a non-cached request?
What is Express.js?
https://github.com/Concatapult/node-catapult/blob/master/server/index.js
Writing files in Node.js
Other options, use a text editor, use sed, grep, awk, bash, or something else that doesn't require serving files to a browser?
Related
I'm learning frontend development and browsing through websites trying to learn from what is on the web. One thing that escapes me is that when I work locally I just make a fetch request to localhost:PORT/... to my backend but I wanted to see what it looks like in production websites, e.g. finding where they make the request + server URL.
How would one download all files from a webpage and then find where an HTTP request is being made in the code?
In my mind it's searching for fetch, XMLHttpRequest, axios or something similar.
I'm working on a decentralized p2p chat system that runs exclusively in the browser. There literally is no server to speak of. I want to persist message history, and IPFS looks like a good way to do that. However, every tutorial and example I can find requires a node.js server, React or Angular (per this)--none of which will work with what I've built.
I have identified some public IPFS gateways that I could potentially use here. But without a server hosting the IPFS api, and no html/javascript exclusive examples, how can I build this?
One idea I was going to explore was running node with express in the browser, which I've done in the past for other projects not using IPFS. But I would like to avoid that if possible.
Is using IPFS without a server hosting the page impossible at this time? What am I missing/overlooking?
I found my own answer and was able to successfully upload and retrieve a file from IPFS using js-ipfs.
One caveat is the example code in index.html at the GitHub link is referencing a local node.js module.
Simply replace:
<script src="./node_modules/ipfs/dist/index.min.js"></script>
With:
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
I have a web application with a client that receives data from a server. I have the data in NodeJS, but I want to pass the data to a Javascript file. The Javascript file is included in a HTML file, so I can't make the files communicate with eachother.
I am new to NodeJS, so it can be a stupid question, but anyones help is appreciated
This is for a project where I need have a data stream, and I need to pass it into a web application. I tried to pass the data to different page inside my application and then I tried to get that data on that page inside my web application via Javascript, but I couldn't make that work. I'm not even sure if its possible at this point.
Your node server can't communicate with your front-end without a specific way of communication like websocket, you have many other way to communicate with your front-end as node-server, take a look at server send event for example.
By the way your front-end can call your node server more easely with a get request as said #tomerpacific in comment.
For that you have to open a route with your express app. Routing with express
And for call it on a GET request, for that you can use the XMLHttpRequest, and if you have implemented jQuery on your front, you can use Ajax jQuery.
I know this is kind of weird and not secure at all, but is there a way of displaying a bash shell with a remote control on the machine where the webapp is running ?
I would like to have a bash interpreter running directly in the webapplication in flask, does anyone knows how to do such a thing ?
Thanks a lot,
If my post wasn't clear enough just tell me and I will try to improve it.
You can create an interface that looks like you opened a new terminal. To do so, create a form, and everytime you hit Enter, you send this data (using jQuery.ajax for instance) to the server.
On the server side, use subprocess to run the commands you get from the server. You might need to parse this data (something like: my_string.split(' ')) in order to get the argument in a list. You can return the result of that command using: subprocess.check_output in a JSON data type to the client. With Javascript (and jQuery) you can now parse that data and display it wherever you want.
I am trying to write a small documentation tool to be used from the browser. It would need to fetch source code files from a web server. What would be the appropriate way to fetch files from JavaScript itself and then read them so they can be parsed ? The file to be fetched is on a different web server.
thanks in advance,
vivekian
Use some sort of ajax framework (or XmlHttpRequest) that would read a file, parse it and display it.
You'll have to create a proxy to that other server. Otherwise you're going to run into security exceptions.
Given your main url http://www.x.com/help.html, and the source files that are located at http://www.x321.com/src/, you're going to create a proxy at http://www.x.com/proxy/ to http://www.x321.com/src/