diff --git a/express-examples/express2.js b/express-examples/express2.js index 21dbefc..3fac856 100644 --- a/express-examples/express2.js +++ b/express-examples/express2.js @@ -3,6 +3,8 @@ const express = require('express'); const app = express(); +app.use(express.static('./')); + app.get('/api/contacts', getContacts); app.get('/api/contacts/:id', getContact); diff --git a/promises.js b/promises.js new file mode 100644 index 0000000..7f3fe75 --- /dev/null +++ b/promises.js @@ -0,0 +1,30 @@ + +var promise = Promise.resolve(1); // vs. Promise.reject(new Error('failed')); + +promise.then(result => { + console.log('1: ' + result); + + return getData(result); +}).then(result => { + console.log('2: ' + result); + + return 1; +}).then(result => { + // no return +}).then(result => { + throw new Error('sth bad happened'); +}).then(result => { + // skipped +}).catch(error => { + // process error + // throw error + // return 1 +}).then(result => { + // executed if catch + // does not throw +}); + +function getData() { + return Promise.resolve('some data'); + // return Promise.reject(new Error('no data')); +}