Have a Discord Bot with a Website Attached!


#1

I currently have:

const http = require('http');
const express = require('express');
const app = express();
app.get("/", (request, response) => {
  console.log(Date.now() + " Ping Received");
  response.sendStatus(200);
});
app.listen(process.env.PORT);
setInterval(() => {
  http.get(`https://chef.glitch.me/`);
}, 280000);

In my Discord Bot Code, but I also want to have a attached website to it. But to keep the website up and working I need to have in my server.js:

// server.js
// where your node app starts

// init project
const express = require('express')
const app = express()

// we've started you off with Express, 
// but feel free to use whatever libs or frameworks you'd like through `package.json`.

// http://expressjs.com/en/starter/static-files.html
app.use(express.static('public'))

// http://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
  response.sendFile(__dirname + '/views/index.html')
})

// listen for requests :)
const listener = app.listen(process.env.PORT, () => {
  console.log(`Your app is listening on port ${listener.address().port}`)
})

How can I have both in one project?


#2

Yes, the app.get is setting a route - in this case for the root of your project. But there’s nothing to stop you from adding a route for say /ping, which would be for waking your bot while using the root one and others for your website. See https://expressjs.com/en/starter/basic-routing.html for more info.


#3

Okay, cool thank you :slight_smile: I also am having this error when I start up my bot / project the error is:

ERROR  EINVAL: invalid argument, readlink '/rbd/pnpm-volume/55faa5fe-7745-4043-9e03-cdb5502a083a/node_modules/pako'

and It also says something on the lines of Your project is taking longer than 5 minutes to stop

or something like that. Is there any way I can fix these two issues?


#4

If you share your project name, we can take a look into these. If your project is private, either make it public or DM me a join link. Thanks.