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
| module.exports = function (req, res, next) { | |
| var render = res.render; | |
| res.render = function () { | |
| var viewName = arguments[0], | |
| withoutExtension = viewName.replace(/\.[a-z]+$/i, ""), | |
| bodyClass = withoutExtension.replace(/\//g, "-"); | |
| res.locals.bodyClass = bodyClass; | |
| render.apply(this, arguments); |
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
| $ node | |
| > http.STATUS_CODE | |
| { | |
| '100': 'Continue', | |
| '101': 'Switching Protocols', | |
| '102': 'Processing', | |
| '200': 'OK', | |
| '201': 'Created', | |
| '202': 'Accepted', | |
| '203': 'Non-Authoritative Information', |
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
| 'use strict' | |
| const timeout = ms => new Promise(res => setTimeout(res, ms)) | |
| function convinceMe (convince) { | |
| let unixTime = Math.round(+new Date() / 1000) | |
| console.log(`Delay ${convince} at ${unixTime}`) | |
| } | |
| async function delay () { |
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
| module.exports = { | |
| filters: { | |
| stylus: function (str, opts) { | |
| let ret | |
| str = str.replace(/\\n /g, '') | |
| const styl = require('stylus') | |
| styl(str, opts).render(function (err, css) { | |
| if (err) throw err | |
| ret = css.replace(/\s/g, '') | |
| }) |
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
| { | |
| "AF":{ | |
| "name":"Afghanistan", | |
| "divisions":{ | |
| "AF-BDS":"Badakhshān", | |
| "AF-BDG":"Bādghīs", | |
| "AF-BGL":"Baghlān", | |
| "AF-BAL":"Balkh", | |
| "AF-BAM":"Bāmīān", | |
| "AF-FRA":"Farāh", |
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
| [ | |
| { | |
| "value": "Dateline Standard Time", | |
| "abbr": "DST", | |
| "offset": -12, | |
| "isdst": false, | |
| "text": "(UTC-12:00) International Date Line West", | |
| "utc": [ | |
| "Etc/GMT+12" | |
| ] |
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
| [ | |
| { | |
| "name":"Afghanistan", | |
| "alpha-2":"AF", | |
| "country-code":"004" | |
| }, | |
| { | |
| "name":"Åland Islands", | |
| "alpha-2":"AX", | |
| "country-code":"248" |
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
| [ | |
| { | |
| "entity": "ALGERIA", | |
| "currency": "Algerian Dinar", | |
| "alphabeticCode": "DZD", | |
| "numericCode": "012", | |
| "minorUnit": "2" | |
| }, | |
| { | |
| "entity": "AMERICAN SAMOA", |
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
| app.route('/v1/users/:email') | |
| // GET https://api.example.com/v1/users/:email | |
| .get((req, res) => { | |
| User.find({ email: req.params.email}, (err, user) => { | |
| if (err) throw err | |
| res.json(user) | |
| }) | |
| }) |
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
| app.route('/users') | |
| .post((req, res) => { | |
| User.count({email: req.body.email}, function (err, count) { | |
| if (count == 0) { | |
| // email doesn't exist | |
| const user = new User() | |
| user.email = req.body.email | |
| user.newsletter = req.body.newsletter | |
| user.save((err) => { |