This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var HttpStatus = require('http-status-codes'); | |
| response.status(HttpStatus.OK).send('ok'); | |
| response.status(HttpStatus.INTERNAL_SERVER_ERROR).send({ | |
| error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var morgan = require('morgan'); | |
| morgan('COBE custom log format -> :method :url :status — :response-time ms'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var multer = require('multer'); | |
| var app = express(); | |
| var upload = multer({ dest: 'uploads/' }); | |
| app.post('/avatar', upload.single('avatar'), function (req, res, next) { | |
| // req.file is the 'avatar' file | |
| // req.body will hold the text fields, if there were any | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var rimraf = require('rimraf'); | |
| rimraf('/some/folder', function (err) { | |
| if (err) { throw err; } | |
| // done | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var axios = require('axios'); | |
| axios.all([ | |
| axios.get('/user'); | |
| axios.get('/items') | |
| ]).then(axios.spread(function (userResponse, itemsResponse) { | |
| // this will be executed only when both requests are completed | |
| console.log('Done'); | |
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var axios = require('axios'); | |
| axios.post('/user', { | |
| name: 'Danijel', | |
| email: 'danijel.vincijanovic@cobeisfresh.com' | |
| }).then(function (response) { | |
| console.log(response); | |
| }).catch(function (error) { | |
| console.log(error); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var morgan = require('morgan'); | |
| morgan(function (tokens, req, res) { | |
| return [ | |
| 'COBE custom format function', | |
| tokens.method(req, res), | |
| tokens.url(req, res), | |
| tokens.status(req, res), | |
| tokens.res(req, res, 'content-length'), '-', | |
| tokens['response-time'](req, res), 'ms' |