Skip to content
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

Update json file #18

Closed
courgette opened this issue Oct 6, 2016 · 6 comments
Closed

Update json file #18

courgette opened this issue Oct 6, 2016 · 6 comments

Comments

@courgette
Copy link

Hi,

(sorry for my english)
I have a gulp task to serve my json file into my folder /datas/data.json and when i start gulp and add some datas, all work well. I stopped my gulp task, open /datas/data.json and all datas added are gone. There is an option to save my data into my static file ?

Thanks you

@GrafGenerator
Copy link
Owner

@courgette
There is no option to do that now, gulp-json-srv creates in-memory db when reads files from gulp pipeline. As a workaround for this you can use router object of json-server to access whole DB object. F.e. like this:

var jsonServer = require("gulp-json-srv");
var server = jsonServer.create();

var dbObj = server.router.db.getState(); // <-- this will give you whole DB at the moment

I understand now that this is the use case that I missed, and saving data back to file is good, I think it's candidate for feature request.

@GrafGenerator
Copy link
Owner

Created #19 for feature request.

@GrafGenerator
Copy link
Owner

@courgette Also notice that for example above server.router will ba available after server started (i.e. first file went though pipeline).

@courgette
Copy link
Author

Ok thank you.

The watch task work only on the static file right ? not in datas into the application.

@GrafGenerator
Copy link
Owner

@courgette I'm afraid I don't understood your question right, but anyway, watch task will be watching any file you'll set it to watch and reload server accordingly:) See samples.md for examples of watch task, and reloading server from object, not file.

@courgette
Copy link
Author

Ok thank you, i try that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants