Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

384
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda