Setting up json-server to serve json data for Angular app

The json-server is a simple server to serve json data for playing with Angular app in development. If you are learning AngularJS and want to play with json data you can use this json-server to serve static content for you!!

Installing json-server:

npm install json-server -g

 

Setting up a folder to serve:

Create a folder at any convenient place.

mkdir foldername

Move to that folder

cd foldername

Place your .json file in this folder eg: db.json To serve your content

$json-server --watch db.json

\{^_^}/ hi!

Loading db.json
Done

Resources
http://localhost:3000/dishes
http://localhost:3000/promotions
http://localhost:3000/leadership
http://localhost:3000/feedback

Home
http://localhost:3000

Type s + enter at any time to create a snapshot of the database
Watching...

Now open your favourite browser and navigate to the said links you can see your json being served!!

If you want to serve images or any other static content then you need to put those in public folder.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s