Git Product home page Git Product logo

my-app-server's Introduction

JSON Server Template

Setup

Fork and clone this repo. Then install the dependencies by running:

npm install

Seeding Data

To set up your database, update the db/seeds.json file to contain an object with a key pointing to an array of data, like this:

{
  "toys": [
    {
      "id": 1,
      "name": "Woody",
      "image": "http://www.pngmart.com/files/3/Toy-Story-Woody-PNG-Photos.png",
      "likes": 8
    },
    {
      "id": 2,
      "name": "Buzz Lightyear",
      "image": "http://www.pngmart.com/files/6/Buzz-Lightyear-PNG-Transparent-Picture.png",
      "likes": 14
    }
  ]
}

Then, run npm run seed to copy data from the db/seeds.json file to the db/db.json file. json-server uses the db.json file to create your RESTful API, so make sure your db.json file is always up to date!

Any time you want to reset your database back to your original data, run npm run seed again. Doing this will overwrite all the data in your db.json file, so make sure you don't have any data in that file that you don't mind losing!

Running the Server Locally

To run your server in development mode, run:

npm run dev

While running in development mode, the server will re-load any time you make changes to the db.json file, so you can test our your seed data.

While your server is running, you can make requests to http://localhost:3000. Check it out in the browser to make sure your server works!

Deploying the Server

Free services like Heroku make it simple to deploy your Node server. Heroku also works nicely with Rails, which you'll learn later in the program.

First, download the Heroku CLI.

Then, deploy your app.

Since Heroku deployment integrates with your git repo, you can easily deploy changes to your database. To deploy changes, make sure to commit your code:

git add .
git commit -m "Updated database"

Then push your main/default branch up to Heroku:

git push heroku main

my-app-server's People

Contributors

mdquayle avatar ihollander avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.