Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var port = 3000;
- var today = require('./today');
- var express = require('express');
- var app = express();
- var request = require('request');
- app.get('/api/today', function(req, res) {
- var body = "The day of the week is " + today() + ".";
- res.type('text/plain');
- res.set('Content-Length', Buffer.byteLength(body));
- res.status(200).send(body);
- });
- app.get('/api/weather', function(req, res) {
- var options = {
- method: 'GET',
- uri: 'http://weather.gov/xml/current_obs/KSFO.xml',
- headers: {
- 'User-agent': 'weatherRequest/1.0'
- }
- };
- var callback = function(error,response,body) {
- res.type('text/plain');
- rest.status(response.statusCode).send(body);
- };
- request(options, callback);
- });
- app.listen(port, function() {
- console.log('Listening on port %s.', port);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement