Website and project?

#1

my project is node express, i host my discord bot but i want to run my site in my project because i can connect bot database to my site

1 Like

#2

Hey @gco360, this is a pretty common combination that many Discord bot projects use. My project https://glitch.com/~discordjs-bot-extended is a very simple example; if you look at server.js you can see how Express is configured to respond to requests.

Based on that you can set up your own routing for a site or use static files - what you do from there is limited only by your imagination!

Let us know if you need additional information!

1 Like

#3

no i mean running your bot and website together in the same project can you do that ?

1 Like

#4

Hello @gco360,

Follow these steps to get what you are looking for! :slight_smile:

  • Create a new javascript file.
  • Name the file server.js (Or whatever you would like to name it)
  • Put this code into the file:
let mainFileDirectory = " "

var express = require('express');
var app = express();
var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});
app.use(express.static('public'));

app.get('/', function(request, response) {
  response.sendFile(mainFileDirectory);
});

  • Put the location of your html file that you want to be loaded first with the web url into mainFileDirectory
  • Go to your main file, put the following:
require('/app/fileName.js')

replace fileName.js with the name that you gave the javascript file.

and you SHOULD be done

any problems make sure to let me know!

0 Likes

#5

Hey dude! what i understand is that you would like to link your discord bot with your glitch website. I assume you are using express, so you should check out socket.io

0 Likes

#6

I didn’t understand this can u help me out because im using express to run my bot on the same project

0 Likes