-
-
Save christiannwamba/e821e83f5cd4461cdcc831331746d10b to your computer and use it in GitHub Desktop.
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 express = require('express'); | |
var path = require('path'); | |
var favicon = require('serve-favicon'); | |
var logger = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); | |
var Pusher = require('pusher'); | |
var pusher = new Pusher({ | |
appId: "Pusher_App_Id", | |
key: "Pusher_App_Key", | |
secret: "Pusher_App_Secret", | |
encrypted: true, | |
cluster: "Puser_App_Cluster" | |
}); | |
var app = express(); | |
// uncomment after placing your favicon in /public | |
//app.use(favicon(__dirname + '/public/favicon.ico')); | |
app.use(logger('dev')); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
app.use(cookieParser()); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.post('/records', function(req, res){ | |
var record = { | |
name: req.body.nametxt, | |
age: req.body.agetxt, | |
position: req.body.positiontxt, | |
address: req.body.addresstxt, | |
} | |
//publish event | |
pusher.trigger('table', 'new_record', record); | |
res.json({success: 200}); | |
}); | |
// catch 404 and forward to error handler | |
app.use(function(req, res, next) { | |
var err = new Error('Not Found'); | |
err.status = 404; | |
next(err); | |
}); | |
//start server | |
app.listen(3000, function () { | |
console.log('Node server running on port 3000'); | |
}); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment