-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Could json-server watch multiple files #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this is not a good solution, but it is easy to implement. I used
// index.js
const user = require('./src/user.json')
const article = require('./src/article.json')
module.exports = () => ({
users: [user, user],
articles: [article, article]
}); // update.js
const fs = require('fs')
const text = fs.readFileSync('./index.js', 'utf-8')
fs.writeFileSync('./index.js', text, 'utf-8') File structure
Setup scripts in {
"scripts": {
"start": "concurrently --kill-others \"npm run start:server\" \"npm run update:watch\"",
"start:server": "json-server --watch index.js",
"update:watch": "onchange 'src/**/*.json' -- node update"
}
} |
@zugarzeeker Nice implementation 👍 "update:watch": "onchange 'src/**/*.json' -- touch index.js" |
@typicode Thanks for your suggestion. |
I'm using nodemon to restart and watch multiple files. So, I'm serving my mock files from mock folder. "scripts": {
"mock": "nodemon --watch mock --exec 'json-server --port 6002 mock/db.js --routes mock/routes.json'"
} module.exports = function() {
return {
users: require('./data/users'),
companies: require('./data/companies')
}
}; |
@zugarzeeker Thanks for the solution. Though I'm not sure if your approach is supposed to work with POST requests ... is it? Because I'm able to to retrieve data, but I'm not able to update the json files. So before I dig deeper, I just wanted to make sure if this doesn't work by purpose. |
None of these suggestions worked for me :( It really seems like this should be out-of-the-box functionality… |
use
|
I have massive data and I don't want put them in the same file. So could I separate them into multiple files and watch them at the same time?
The text was updated successfully, but these errors were encountered: