Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

380
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!