- User can get a list of snacks
- User can add a snack
- User can edit a snack
- User can delete a snack
- Fork, clone, npm install
$ npm start
- go to (http://localhost:3000/)[http://localhost:3000/] and be greeted
$ curl http://localhost:3000/
and be greeted
$ express snacks-pg
$ cd snacks-pg
$ touch README.md
, open in your favorite editor and start taking AMAZING NOTES.$ npm install
$ npm start
to start the server and check it out (http://localhost:3000/)[http://localhost:3000/]- install jasmine-node
$ npm install --save-dev jasmine-node
- Ensure you have jasmine-node globally installed
$ jasmine-node
- if not installed,
$ npm install -g jasmine-node
- Make a spec directory in the project root and
$ touch spec/test.spec.js
- add the following contents to
spec/test.spec.js
:
describe("test setup", () => {
it("is setup", () => {
expect(true).toBe(false);
});
});
- Open
package.json
and add a new script called "test" with a value of "jasmine-node spec/" (follow pattern for "start" script) - Run the test
$ npm test
. Make sure the test fails, then change false to true and COMMIT. yay. $ git init
$ echo node_modules >> .gitignore
$ git add .
- Commit all changes
$ mv spec/test.spec.js spec/welcome.spec.js
- Add the package request to dev dependencies
$ npm install --save-dev request
- 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();
});
});
});
- 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.
- 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
- Commit new changes