0

I'm trying to make some mockup data and call it. since my backend is not completed yet .

1
  • You can try with json-server Commented Nov 19, 2021 at 11:13

2 Answers 2

2

You could serve the JSON locally. You could run something like json-server in the background, say on port 5000, and make your requests to http://<your computer's ip>:5000.

Note: don't use http://localhost:5000 - this will only work on the iOS simulator, since it's the only "device" that shares your local machine's network config. Get the IP address of your computer and use that instead.

Sign up to request clarification or add additional context in comments.

Comments

1

I believe reading a local file with Axios is a wrong approach.

Check this link: https://dev.to/buaiscia/mock-an-axios-call-with-a-json-file-1j49

Instead, I recommend using FileSystem!

You can read local data in javascript using FileSystem. Steps:

  1. Install fs

    npm install fs
    
  2. Import fs in file

    var fs = require('fs')
    
  3. Then read the file:

    fs.readFileSync('fileName.json');
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.