I'm trying to use json-server to generate some fake data. Here is the Node.js code:
// data.js
function generateData1() {
test = [];
return {
"test": test
}
}
function generateData2() {
test = [];
return {
"test": test
}
}
module.exports = {
generatePredixData: generatePredixData1,
generatePredixLatestData: generatePredixData2
}
When trying to run json-server data.js
it throws the following error:
the database is a javascript file but the export is not a function
Here is the full stack trace:
D:\FakeData>json-server data.js
\{^_^}/ hi!
Loading data.js
C:\Users\jay.r\AppData\Roaming\npm\node_modules\json-server\lib\cli\utils\load.j
s:28
throw new Error('The database is a JavaScript file but the export is not a
function.');
^
Error: The database is a JavaScript file but the export is not a function.
at module.exports (C:\Users\jay.r\AppData\Roaming\npm\node_modules\json-serv
er\lib\cli\utils\load.js:28:13)
at start (C:\Users\jay.r\AppData\Roaming\npm\node_modules\json-server\lib\cl
i\run.js:119:5)
at module.exports (C:\Users\jay.r\AppData\Roaming\npm\node_modules\json-serv
er\lib\cli\run.js:156:3)
at module.exports (C:\Users\jay.r\AppData\Roaming\npm\node_modules\json-serv
er\lib\cli\index.js:76:3)
at Object.<anonymous> (C:\Users\jay.r\AppData\Roaming\npm\node_modules\json-
server\lib\cli\bin.js:3:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)