Moved the Moralis.start call outside off the app.get. Runs as intendedโฆ here is code.
const express = require('express')
const app = express()
const port = 8080
const Moralis = require('moralis').default
const cors = require('cors')
require('dotenv').config()
app.use(cors())
const MORALIS_API_KEY = process.env.MORALIS_API_KEY
app.get('/', (req, res) => {
res.send('gm mfers')
})
app.get('/nativeBalance', async (req, res) => {
try {
const { address, chain } = req.query
const response = await Moralis.EvmApi.balance.getNativeBalance({
address: address,
chain: chain,
})
const nativeBalance = response
res.send(nativeBalance)
} catch(e) {
res.send(e)
}
})
Moralis.start({
apiKey: MORALIS_API_KEY
}).then(() => {
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
})```