Skip to content

Instantly share code, notes, and snippets.

@ihollander
Last active May 1, 2024 16:11
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • 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.

@iCiera
Copy link

iCiera commented May 2, 2022

Sweet!

@MolenaMo
Copy link

MolenaMo commented May 7, 2022

Nice! ^-^

@the-alchemist-gh
Copy link

Thank you for this.

@citixenken
Copy link

@Kaburu12
Copy link

great

@davidnene
Copy link

Thank you

@KennethAlbert
Copy link

nice....

@ochienghesbon
Copy link

thanks

@Ogalo
Copy link

Ogalo commented Jun 16, 2022

Nice.

@ggkm3251
Copy link

Nice

@Georgekinyanjui1
Copy link

thank you

@Bright-ship-it
Copy link

How did you guys do it?

@Victoria-Musyoka
Copy link

perfect

@Teenskey-Knows
Copy link

Thank you even though I didn't understand anything

@Teenskey-Knows
Copy link

How did you guys do it?

When you go to the package.json
Copy paste the entire code as the last code within the curly braces.

But also ensure that you have a comma to separate where the copy pasted code begins & the previous code.

@Victorious001
Copy link

Thank you.

@KwaiNks
Copy link

KwaiNks commented Oct 16, 2022

cool

@sereyatiampati
Copy link

My Vs Code on Ubuntu has three preferences setting. Where should I add?
Screenshot from 2022-12-03 06-37-45

@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