If you mean being sending HTTP requests to the Heroku App URL, then yes.
If you want to receive a message from your Node.js server, then here’s how you can do it.
You’ll need to utilize a POST HTTP request in order to receive messages. POST requests send data to a server.
There are many ways you can recieve POST requests, however, I usually do it like this. You’ll need to install two npm packages - express.js and body-parser.
From the command line, initialize a project if you haven’t already:
npm init
Then, execute these two commands (make sure npm is installed!)
npm install express
npm install body-parser
Now, enter in this code in a .js file:
const express = require('express')
const bodyparser = require('body-parser')
const app = express()
var port = 8000
app.use(bodyparser.text())
app.post('/post', (request, response) => {
response.send("Gotten POST request")
console.log(request.body)
})
app.listen(port, function(){
console.log(`started server at http://localhost:${port}`)
})
Start the server via node index.js
(or whatever your file name is).
Test it out by sending a POST request from Roblox:
local HttpService = game:GetService("HttpService")
local options = {
Url = "http://localhost:8000/post", -- or whatever url. this is mainly for example purposes.
Method = "POST",
Headers = {
["Content-Type"] = "text/plain"
},
Body = "Hello world!"
}
local success, msg = pcall(function()
local response = HttpService:RequestAsync(options)
if response.Success then
print("Status code:", response.StatusCode, response.StatusMessage)
print("Response body:\n", response.Body)
else
print("The request failed:", response.StatusCode, response.StatusMessage)
end
end)
if not success then
print(msg)
end