1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 18:32:50 +00:00

added more api's. Fixed data types for temperature schema

This commit is contained in:
2015-12-19 01:40:27 -06:00
parent 73da2b5020
commit da4140ddea
8 changed files with 100 additions and 21 deletions

View File

@@ -12,7 +12,7 @@ var http = require('http');
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '80');
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**

View File

@@ -1,8 +1,8 @@
var mongoose = require('mongoose');
var temperatureSchema = new mongoose.Schema({
temperature: String,
humidity: String,
temperature: Number,
humidity: Number,
location: String,
updated: {type: Date, default: Date.now}
});

39
npm-debug.log Normal file
View File

@@ -0,0 +1,39 @@
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files (x86)\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\Mitchell\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@2.14.1
3 info using node@v4.1.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart myapp@0.0.0
6 info start myapp@0.0.0
7 verbose unsafe-perm in lifecycle true
8 info myapp@0.0.0 Failed to exec start script
9 verbose stack Error: myapp@0.0.0 start: `forever ./bin/www`
9 verbose stack Exit status 1
9 verbose stack at EventEmitter.<anonymous> (C:\Users\Mitchell\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:214:16)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at EventEmitter.emit (events.js:172:7)
9 verbose stack at ChildProcess.<anonymous> (C:\Users\Mitchell\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:24:14)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at ChildProcess.emit (events.js:172:7)
9 verbose stack at maybeClose (internal/child_process.js:817:16)
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid myapp@0.0.0
11 verbose cwd C:\Users\Mitchell\desktop\mywebsite
12 error Windows_NT 6.1.7601
13 error argv "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Users\\Mitchell\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
14 error node v4.1.1
15 error npm v2.14.1
16 error code ELIFECYCLE
17 error myapp@0.0.0 start: `forever ./bin/www`
17 error Exit status 1
18 error Failed at the myapp@0.0.0 start script 'forever ./bin/www'.
18 error This is most likely a problem with the myapp package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error forever ./bin/www
18 error You can get their info via:
18 error npm owner ls myapp
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

View File

@@ -17,10 +17,10 @@
<a href="/">Home</a>
</li>
<li>
<a href="experience">My Experience</a>
<a href="/experience">My Experience</a>
</li>
<li>
<a href="sensors">Sensors</a>
<a href="/sensors">Sensors</a>
</li>
<li>
<a href="mailto:mgerber11@winona.edu">Contact</a>

View File

@@ -7,15 +7,13 @@ var temperature = mongoose.model('temperature');
/* GET sensors page. */
router.get('/tempsensors', function(req, res, next) {
router.get('/allsensors', function(req, res, next) {
//var location = req.query.location;
temperature.aggregate([ {$sort : {location : -1, updated : -1}},
{ $group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}}]).exec(function(err, info){
temperature.aggregate([{$group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}},
{$sort : {"_id.month" : -1, "_id.day" : -1, "_id.year" : -1}}]).exec(function(err, info){
console.log(info);
res.setHeader('Content-Type', 'application/json');
@@ -23,11 +21,25 @@ router.get('/tempsensors', function(req, res, next) {
});
});
router.get('/sensorbylocation', function(req, res, next) {
var loc = req.query.location;
console.log(loc);
//var location = req.query.location;
temperature.aggregate([ {$match : {location : loc}},
{$group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}},
{$sort : {"_id.month" : -1}}]).exec(function(err, info){
console.log(info);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(info, null, 4));
});
});
router.post('/', function(req, res,next) {

View File

@@ -0,0 +1,29 @@
<div class="blog-post">
<h2 class="blog-post-title">Understanding Javascript Callbacks</h2>
<p class="blog-post-meta">December 10, 2015 by Mitchell</p>
<p>Javascript is a powerfull language that is being utilized mainly on the front end of applications as well on the back end. Javascript has become popular as a back end language because it is built around asynchronous functionality and features a non-blocking API, which is known as Node.js. Node.js is a cross-platform runtume environment for developing server-side web applications. This site is currently using Node.js as a back end and server platform.
</p>
<hr>
<p>As I have progressed in college I have become more interested in server side programming. I first started out with PHP and JSP, but I wanted to learn a language that was newer, and I liked the idea of Node.js and it's ease of use when it came to creating restful API's. When I first started venturing into web development, I became familiar with javascript and I easily adapted because of my strong background with Java. I cought on to web development very quickly and I wanted to learn new server side languages besides PHP and JSP. I liked the idea of Node.js because I thought it would be convenient to use Javascript for both the back and and front end as well as the database, but that is another story. I also use MongoDB to store the information for this site, but I will will make another blog post about that in the future.
</p>
<p>I could go on and on about how much I like javascript as a back end programming language, but I wwant to discuss the callback functionality that javascript is very popular for. I want to discuss this because at first I had a hard time understanding the asynchronous functiality of javascript and I would like to help others better understand this concept. Javascript is known as a single threaded language, but it utilizes callbacks within asynchronous functionality to act like a multi-threaded application, which is different than an applications that uses PHP or JSP.
</p>
<p>If you have previously only had experience programming in Java or Python for example you probably have not done much with threading or asynchronous programming. This can make asynchronous javascript functions confusing, because it is probably a new aspect of programming. Because asynchronous Javascript functions have callbacks, all of the proceeding code must be written within the function. I will try to explain this in the examples below.
</p>
<code>
function print_text(){
}
</code>
</div>

View File

@@ -3,11 +3,10 @@
<head>
<title>mitchellg.me</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="/stylesheets/style.css">
<link rel="stylesheet" href="jquery-ui-1.11.4.custom/jquery-ui.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.icon-large.min.css">
<link rel="stylesheet" href="/jquery-ui-1.11.4.custom/jquery-ui.css">
<link rel="stylesheet" href="/bootstrap/css/bootstrap.icon-large.min.css">
<link href="http://fonts.googleapis.com/css?family=Arvo" rel="stylesheet" type="text/css">
</head>

View File

@@ -1,9 +1,9 @@
<script src="jquery-1.11.3.min.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<script src="jquery-ui-1.11.4.custom/jquery-ui.min.js"></script>
<script src="javascripts/custom.js"></script>
<script src="/jquery-1.11.3.min.js"></script>
<script src="/bootstrap/js/bootstrap.js"></script>
<script src="/jquery-ui-1.11.4.custom/jquery-ui.min.js"></script>
<script src="/javascripts/custom.js"></script>
</html>