Giter Club home page Giter Club logo

snacks-pg-express's Introduction

README

TODO (snack crud)

  1. User can get a list of snacks
  2. User can add a snack
  3. User can edit a snack
  4. User can delete a snack

Get this puppy up and running

  1. Fork, clone, npm install
  2. $ npm start
  3. go to (http://localhost:3000/)[http://localhost:3000/] and be greeted
  4. $ curl http://localhost:3000/ and be greeted

How was this thing made?

Basic Express App setup

  1. $ express snacks-pg
  2. $ cd snacks-pg
  3. $ touch README.md, open in your favorite editor and start taking AMAZING NOTES.
  4. $ npm install
  5. $ npm start to start the server and check it out (http://localhost:3000/)[http://localhost:3000/]
  6. install jasmine-node $ npm install --save-dev jasmine-node
  7. Ensure you have jasmine-node globally installed $ jasmine-node
  • if not installed, $ npm install -g jasmine-node
  1. Make a spec directory in the project root and $ touch spec/test.spec.js
  2. add the following contents to spec/test.spec.js:
describe("test setup", () => {
  it("is setup", () => {
    expect(true).toBe(false);
  });
});
  1. Open package.json and add a new script called "test" with a value of "jasmine-node spec/" (follow pattern for "start" script)
  2. Run the test $ npm test. Make sure the test fails, then change false to true and COMMIT. yay.
  3. $ git init
  4. $ echo node_modules >> .gitignore
  5. $ git add .
  6. Commit all changes

User is greeted by API at root

  1. $ mv spec/test.spec.js spec/welcome.spec.js
  2. Add the package request to dev dependencies $ npm install --save-dev request
  3. Change the contents of the file to:
var request = require('request');
var app = require('../app.js');

var baseUrl = 'http://localhost:3000/'

describe('Snacks Root Path', function() {
  it('returns status code 200', function(done) {
    request.get(baseUrl, function(error, response, body) {
      expect(response.statusCode).toBe(200);
      done();
    });
  });

  it('returns a greeting', function(done) {
    request.get(baseUrl, function(error, response, body) {
      expect(body).toBe('Welcome to the Snack Tracker!');
      done();
    });
  });

});
  1. Run your tests. Change the routes/index.js response to:
res.send('Welcome to the Snack Tracker!');

Remove the comment while you are there. Run your tests and make sure you have gone from red to green.

  1. Strip out all server-side rendering cruft code, and re-run tests to make sure you are still green:
  • app.js:
    • remove var favicon = require('serve-favicon');... we won't need a favicon.

    • remove comment regarding favicon and commented code for favicon

      // uncomment after placing your favicon in /public
      //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
    • remove view engine setup lines of code

      // view engine setup
      app.set('views', path.join(__dirname, 'views'));
      app.set('view engine', 'jade');
    • remove line of code to load static files app.use(express.static(path.join(__dirname, 'public')));

    • change the error case to render json as below (in two places):

      res.json({
        message: err.message,
        error: err
      });
  • package.json:
    • remove jade and serve-favicon from dependencies. Make sure you address any trailing comma issues.
    • $ rm -rf node_modules, $ npm install, and restart server.
  • delete public directory
  • delete views directory
  1. Commit new changes

snacks-pg-express's People

Contributors

craftninja avatar

Watchers

Dushyant avatar James Cloos 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.