Skip to content

Instantly share code, notes, and snippets.

View utsukushiihime's full-sized avatar
🎯
Focusing

Crystal McNeil utsukushiihime

🎯
Focusing
View GitHub Profile
@utsukushiihime
utsukushiihime / enum-access.js
Created September 22, 2020 23:29 — forked from bnoguchi/enum-access.js
How to access enumValues in mongoose from a Model or Document
var mongoose = require('./index')
, TempSchema = new mongoose.Schema({
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']}
});
var Temp = mongoose.model('Temp', TempSchema);
console.log(Temp.schema.path('salutation').enumValues);
var temp = new Temp();
console.log(temp.schema.path('salutation').enumValues);
<body>
<h1>Here are all the fruits!</h1>
<a href="/fruits/new">add fruit (+)</a>
<% fruits.forEach((fruit, index) => { %>
<li>
<a href="/fruits/<%= index %>"> <%= fruit.name %> </a>
</li>
<% }); %>
</body>
@utsukushiihime
utsukushiihime / gist:0860ae991781c230658b70ad4b904150
Created September 9, 2020 16:59
Expressjs 404 Error Handling
app.use(function (req, res) {
// any get will send 404
if (req.method === "GET") return res.status(404).send("404 Page Not Found");
// any other method will say not allowed
return res.status(405).send("Method not allowed");
});