json-server icon indicating copy to clipboard operation
json-server copied to clipboard

question: using as memory db inside nodejs app

Open enorrmann opened this issue 1 year ago • 1 comments

I'm trying to use the server as a dev de inside other app, the get method returns undefined, but the data is in the json

is this correct ?

const db = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();

db.use(middlewares);
db.use(router);

// get eventos
function getAllEventos() {
   return db.get('eventos'); // returns undefined
}

the db

{
    "eventos": [
        {
            "id": 1,
            "nombre": "Concierto de Rock",
            "precio": 25.99,
            "fecha": "2023-06-15",
            "descripcion": "Un increíble concierto de rock con bandas populares.",
            "cantidad_maxima_entradas": 1000
        },
        {
            "id": 2,
            "nombre": "Exposición de Arte",
            "precio": 10.50,
            "fecha": "2023-07-05",
            "descripcion": "Una exposición de arte contemporáneo con artistas reconocidos.",
            "cantidad_maxima_entradas": 500
        },
        {
            "id": 3,
            "nombre": "Seminario de Desarrollo Web",
            "precio": 50.00,
            "fecha": "2023-08-20",
            "descripcion": "Un seminario intensivo sobre las últimas tecnologías de desarrollo web.",
            "cantidad_maxima_entradas": 200
        }
    ]
}

enorrmann avatar May 22 '23 02:05 enorrmann