I use node-fetch for make requests to localhost.
I want to use get method for get specific file content.
An example: my node.js server is a file called app.js
, and in the same folder there is a file called config.json
, so I want to get (from a discord bot made with discord.js) the content of config.json.
Here my server's code:
const express = require('express');
const app = express();
const fetch = require('node-fetch');
const fs = require('fs')
const port = process.env.port || 1451
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.sendFile(`my path`, { 'Content-Type': 'text/html' });
});
app.post('/jsonFile', (req, res) => {
console.log(req.body);
})
app.listen(port, () => console.log(`listening on http://localhost:${port}`));
And here is my discord bot code for connecting to my website:
fetch('http://localhost:1451').then(res => console.log(res))
P.S I use express for node.js servers