This is a really small and kinda silly thing that I just felt like sharing.
If you didn’t know already you can run Javascript files, that will be run using NodeJS server-sided.
This makes it possible to set up an express server that will run once you start your resource, no additional programs needed.
Tutorial:
Simply create a new folder in your resources folder and run yarn init
and then yarn add express
in cmd. (Install yarn first if you haven’t…)
Then create a fxmanifest.lua
which will look like this:
fx_version 'bodacious'
games {'gta5'}
dependencies {
'yarn'
}
server_scripts {
'server.js'
}
Than create your express app in server.js
:
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send(`Hello World! I am running on an fxserver with ${GetNumPlayerIndices()} player! 😮`))
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
Now start up your server, start your resource and wait for yarn to do it’s thing . Goto http://localhost:3000
. You can also change the port to 80
to make it accessible under just http://localhost
Voila:
Now you can use Natives right in your express app