Skip to content

Instantly share code, notes, and snippets.

@ihollander
Last active May 1, 2024 16:11
Show Gist options
  • Save ihollander/cc5f36c6447d15dea6a16f68d82aacf7 to your computer and use it in GitHub Desktop.
Save ihollander/cc5f36c6447d15dea6a16f68d82aacf7 to your computer and use it in GitHub Desktop.
Setup instructions for Live Server in VSCode (how to prevent issues working with json-server)

Problem Statement

Live Server is a great tool for working with Javscript. It automatically reloads our code any time changes are made to files in the folder where Live Server is running. This becomes an issue when using a tool like json-server with a .json file in the same directory - since changes you make using POST/PATCH/DELETE requests will update the .json file, these changes will also cause your app to reload.

Solution

You can solve this by telling Live Server to ignore changes to certain files. Open your VSCode preferences by pressing command + shift + p in VSCode and searching for "Preferences: Open Settings (JSON)". Then, add the following lines to the settings.json file:

"liveServer.settings.ignoreFiles": [
  ".vscode/**",
  "**/db.json"
],

This will tell Live Server to ignore changes to any db.json files. You can add other files to this as well if you wish.

@viviandande
Copy link

helpful, thank you

@Irishwolf13
Copy link

Irishwolf13 commented Dec 16, 2022

image

I have the exact same question. Also, if it's Deault Settings (JSON), I keep getting an error that it's not editable.
Any thoughts? =)

@sereyatiampati
Copy link

image

I have the exact same question. Also, if it's Deault Settings (JSON), I keep getting an error that it's not editable. Any thoughts? =)

Add it to the User Settings(JSON), mine worked with the same. I should have updated my post.

@joshuakregg
Copy link

hecka tight!

@ChristopherVuvu
Copy link

Amazing

@wilsonwanjiru-cmd
Copy link

Thank you very much

@kannyg87
Copy link

kannyg87 commented Jul 25, 2023

I have second key value pair is grayed out for me
{
"window.zoomLevel": 1,
"liveServer.settings.ignoreFiles": [
".vscode/",
"
/db.json"
]

}

@hasnahadd
Copy link

nice

@oualidelh
Copy link

nice

you came early

@Karuchiu
Copy link

image
I have the exact same question. Also, if it's Deault Settings (JSON), I keep getting an error that it's not editable. Any thoughts? =)

Add it to the User Settings(JSON), mine worked with the same. I should have updated my post.

Great!

@calebkomen
Copy link

cannot edit in read only editor

@Rotichgideon
Copy link

grate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment