Discord.js create JSON file with server information - javascript

Using discord.json, is there any way I can create a json file containing all information for a specific server? (Roles, channels, etc.)
No, I’m not asking for code. I’m asking whether or not this would be possible and if there’s a function for it.

You could use the core module fs to make files (or a json file for your need)

Related

Is it possible to get JSON from a URL and save it as json file with a custom name inside a specified path/folder through the front end?

My issue is simple on paper - I have a React Native project and I'm trying to make a script that will run on build and fetch JSON from a URL, then save it as JSON file with a custom name inside a specified path/folder. For example, I want to access the JSON at www.example.com and save it as a JSON file in project/src/assets/locales/en.json
The problem is that when I google how to fetch and save JSON, most of the results are related to Node.js and I don't think I can use them. Is what I'm trying to do possible?
Since you've said you're doing this in a git push hook, you can use any of several things for this:
You can indeed use Node.js, by having the hook run it via node, and then using Node.js's http client (to read it) and fs module (to write it to a file).
You can use a shell script, perhaps using with curl or wget (on platforms where those are available).
Since you're already writing JavaScript code for the app itself, Node.js is a reasonable choice.

How to read file client-side without using a file input?

I'm struggling to know how to read a file (client-side) in JS without using a file input, as I only need to read a local file in my project.
What I want to achieve is to get the content from a .less file in order to put it into a parser of some kind (I need to access its content in a javascript file).
I cannot use "fs" as I'm not using node, but I don't seem to be able to use the FileReader API either as it needs a Blob object which would be obtained by the file input.
Does someone have an idea ?
client side doesn't have access to manage file system, you can read file with input but cannot write or delete from client side. it is only possible with a backend application written in node js or java, from their you can expose those services and call it from client side through http requests.

storing info as a JSON file on a server

So I have information i need to save. I am using a JavaScript object then I store the info in a JSON file.
But I want to put my project on a server and run it. but currently I am using fs to read and write data.
how would i do that on a server
You can have the JSON file in the server and read/write to it the same way you are doing locally, it makes no difference.
That said, I'd recommend using something like http://npmjs.com/package/json-server to make it work like an actual server API.

Node.js - Pipe a file stream from one server to another

I'm trying to use Node.js to get a file from a remote URL then send it to another server (using an API provided by each of the two websites). I already managed to successfully upload a local file to the remote server using fs.createReadStream("file.png"). Remote files seem to be a different story however: I can't simply put "https://website.com/file.png" in there, I need an equivalent for createReadStream for remote files.
Obviously I could use a separate command to download the file locally and upload it using createReadStream then delete the local file, but I want my code to be efficient and not rely on manually downloading temporary files, plus this is a good learning experience. I'd thus like to know the simplest way to pipe files as streams between two different servers.
Also I would like to avoid using extra dependencies if possible, as I'm writing a simple script which I'd rather not make reliant on too many npm packages. I rely on require("https") and require("fs") primarily. I'm curious if this can be achieved through a simple https.get() call.

What's the common way to access a MongoDB with JavaScript?

Let's say I wrote a little HTML site, deployed on my nginx webserver. I created a database with MongoDB and stored several million entries in it. The MongoDB server is only listening on the local interface and accessible via localhost:27017.
Now I want to go to my webpage on my publicly accessible nginx webserver and access the entries in the database via JavaScript, by clicking a button "Show Users" or "Get latest entries" and so on. I need to perform only simple read-only-queries on the database like counting, searching, aggregating, and so on, so I don't need write access.
How do you generally implement this? Do I really need to set up PHP, Python, and Java to access the DB or is it somehow possible to solve this by only using HTTP/REST Interfaces? Can NodeJS help me to solve this? Do I have to remove nginx when using NodeJS?
Sorry, but I'm quite confused with all that JavaScript/ NodeJS/ mongoose/ MongoDB/ JSON stuff.
You can keep nginx as server for static content like your html files. To serve dynamic data, use node.js to create a rest interface. The rest interface will provide the data it fetches from your MongoDb.
Since you have millions of entries in your database and do not require complex functionality I would recommend the mongodb-native-driver as node.js module.
On the client, use ajax to perform api calls to your created rest interface.
Mongoose is built on top of the native driver to allow object modeling.

Categories

Resources