This file contains 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
function add (a, b) { | |
return a + b | |
} | |
var result = add(1, 2); | |
console.log(result); |
This file contains 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
User.find({}).then(function (users) { | |
// Do something with the users data | |
}, function (err) { | |
// Do something with the error | |
}); |
This file contains 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 argv = require('yargs') | |
.command('Hello', 'Greets the User', function(yargs){ | |
return yargs.options({ | |
name: { | |
demand: true | |
} | |
}); | |
}) | |
.argv; | |
var command = argv._[0]; |
This file contains 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 obj = { | |
age: 99, | |
someFunc: function () { | |
console.log('age', this.age); | |
} | |
} | |
// Uses the default this definition which would be the obj object | |
obj.someFunc(); |
This file contains 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.use(function (req, res, next){ | |
if (req.headers['x-forwarded-proto'] === 'https') { | |
res.redirect('http://' + req.hostname + req.url); | |
} else { | |
next(); | |
} | |
}); |
This file contains 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
/** | |
* In the following example, the code in the try block will trigger the catch block | |
* without explicitly calling "throw new Error('error message')" | |
* | |
* When you try to reference a variable that does not exist, Node itself will throw | |
* the error. | |
*/ | |
try { | |
console.log(varNotReal); |
This file contains 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": "t", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"build": "webpack ./public/app.js ./public/bundle.js" | |
}, | |
"author": "", |
This file contains 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
import { ADD_TO_CART } from '../actions/index'; | |
export default function(state = [], action) { | |
switch(action.type) { | |
case ADD_TO_CART: | |
return [ | |
...state, | |
action.payload | |
]; | |
default: |
This file contains 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.get('/user', function(req, res) { | |
db.user.findAll().then(function(user) { | |
res.json(user.toPublicJSON()); | |
}), | |
function(e) { | |
res.status(500).send(); | |
} | |
}); |
This file contains 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
// EXAMPLE ONE | |
var foo = 'Andrew'; | |
console.log(foo); // 'Andrew' | |
function foo () { | |
return 'From foo function' | |
} | |
console.log(foo()); // 'From foo function' |