Skip to content

Instantly share code, notes, and snippets.

View WillieYang's full-sized avatar
🎧
Focusing

Willie Yang WillieYang

🎧
Focusing
View GitHub Profile
@WillieYang
WillieYang / req_body.js
Created July 1, 2017 16:46
Cannot use req.body.name to get data in the form
module.exports.searchResults = function(req, res){
var search = req.body.search;
console.log("query:" + search);
renderSearchResults(req, res);
};
// the type of form should be posted, req.body can only get the posted data.
@WillieYang
WillieYang / status_500.js
Last active August 6, 2017 18:02
HTTP error: status code ~ 500
responseBody[object Object],[object Object],[object Object]
These two vars are equal.
GET /locationlist/ 500 197.178 ms - 1964
GET /bootstrap/css/pulse.bootstrap.css 304 1.410 ms - -
// Why would this error happen?
// The reason might be that the data in the view cannot match the controller.
GET / 500 19.940 ms - 1838
GET /bootstrap/css/pulse.bootstrap.css 304 1.349 ms - -
@WillieYang
WillieYang / err.js
Created June 26, 2017 17:06
When using Heroku local, if I use a port which is not port:3000, it would be failed
// error message:
5:55:25 PM web.1 | /home/sheng/Work/smr_pjt_loct_dr/app_server/controllers/locations.js:52
5:55:25 PM web.1 | if (response.statusCode === 200 && data.length) {
5:55:25 PM web.1 | ^
5:55:25 PM web.1 | TypeError: Cannot read property 'statusCode' of undefined
5:55:25 PM web.1 | at Request._callback (/home/sheng/Work/smr_pjt_loct_dr/app_server/controllers/locations.js:52:15)
5:55:25 PM web.1 | at self.callback (/home/sheng/Work/smr_pjt_loct_dr/node_modules/request/request.js:188:22)
// and it is actually weird, trying to figure out...
@WillieYang
WillieYang / gist:f854af0459e5ab1e70ac81e205702a0a
Last active June 21, 2017 14:54
When using the GeoNear() funcition in Mongoose, cannot get the ideal result(the result is empty)
// But when input the exact the same coordinate of a place I have stored in the database, it would be revealed.
// As for GeoJSON format, the unit of distance is meters.
// GeoJSON Multipoint require 2dsphere:
{
type: "MultiPoint",
coordinates: [
[ -73.9580, 40.8003 ],
[ -73.9498, 40.7968 ],
[ -73.9737, 40.7648 ],
[ -73.9814, 40.7681 ]
@WillieYang
WillieYang / gist:6d74a339bae2b714a6d68060d5fbc0e7
Last active June 21, 2017 14:57
Why cannot get the review when filter it by id() method.
// The reason is that the id()method only match the field whose name is _id.
// The id of subdocument can be specified using ObjectID(), but it need to be specified into a form of _id.
"reviews" : [
{
"author" : "Jack Lee",
"_id" : ObjectId("5937bd3e8f3da38b9429bba2"),
"rating" : 5,
"timestamp" : ISODate("2017-05-15T23:00:00Z"),
"reviewText" : "Quite, and the coffee is yummy!!!"
}