-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
How can I get random data #70
Comments
are you running your script like
|
You need to create it first: // db.js
module.exports = function() {
data = { users: [] }
// Create 1000 users
for (var i = 0; i < 1000; i++) {
data.users.push({ id: i, name: 'user' + i })
}
return data
} You can also use modules like https://github.com/Marak/faker.js or https://github.com/boo1ean/casual to create random data. |
I've been using mockaroo.com for random data. Nice little UI if you feel like getting something quick and realistic. |
Good point about mockaroo 👍 There's json-generator that seems pretty popular among JSON Server users too. By the way, if the service offers a URL for the schema, you don't even need to download the file. JSON Server can load it:
|
Can I suggest chance.js? I think it's pretty awesome. |
Didn't know chance.js, cool stuff (I've added it to the README alongside other node generators) |
I was wondering if its possible to have random data generated for each request? I have copied the random data example provided and added faker, however each time I hit the mock API the same data is returned. Am I missing something? I just want to simulate polling a server where the data changes. |
I think you'd have to change it here:
When |
thanks for the reply, I was playing around with that file and the router.get() method is hit when you load up the JSON Server Index page (eg http://localhost:3000/) not when i hit the route (eg. http://localhost:3000/ramp) . Not sure I follow your approach? |
I would like some random data.
I creat db.js:
but still return old data
What should I do ?
The text was updated successfully, but these errors were encountered: