Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

387
Visualizações
Lowdb (json database) with Next.js via Netlify returns internal server error 500 on API route, works locally

I've got a really simple JSON flat file db setup that works when running locally but doesn't work once it's hosted on Netlify. I don't get any other error info besides a 500 error on the server. I get the error even if all I do is import the clusterDB object, so something is happening with the lowdb object. I've also tried using another json db library called StormDB and I get the same issue.

Return my API route with a static import of the json file (no db libraries) also works fine.

I'm new to Next.js and this seems related to maybe the SSR portion of things since the API routes run only on the server? Do I need to structure my files differently? Are these libraries not compatible? Lowdb says it works with Node, and everything works locally for me.

Here is my db init file (root/db/db.js)

import {Low, JSONFileSync} from 'lowdb'

// Cluster DB Setup
const adapter = new JSONFileSync('cluster-db.json')
const clusterDB = new Low(adapter)

// Initialize if empty
clusterDB.read()
clusterDB.data ||= { clusters: [] }
clusterDB.write()

export {clusterDB}

And my only API route (root/pages/api/clusters.js)

import {clusterDB} from '../../db/db'

export default async function handler(req, res) {

    await clusterDB.read()

    switch(req.method) {

        case 'POST':
            let newCluster = {severity: req.query.severity, comments: req.query.comments, date: req.query.date}
            clusterDB.data.clusters.push(newCluster)
            clusterDB.write()
            res.status(200).json({status: "Success", cluster: newCluster})
            break;

        case 'GET':
            if(clusterDB.data.clusters) {
                res.status(200).json(clusterDB.data.clusters)
            } else {
                res.status(404).json({status: "404"})
            }
            break;

    }

    res.status(200).json({test: "yay"})
}

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda