Skip to content

Instantly share code, notes, and snippets.

View davinci2015's full-sized avatar
👨‍💻

Danijel Vincijanović davinci2015

👨‍💻
View GitHub Profile
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)
});
var morgan = require('morgan');
morgan('COBE custom log format -> :method :url :status — :response-time ms');
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
});
var rimraf = require('rimraf');
rimraf('/some/folder', function (err) {
if (err) { throw err; }
// done
});
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');
}));
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);
});
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'