Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Forked from kenny-io/app.js
Last active January 17, 2018 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannwamba/e821e83f5cd4461cdcc831331746d10b to your computer and use it in GitHub Desktop.
Save christiannwamba/e821e83f5cd4461cdcc831331746d10b to your computer and use it in GitHub Desktop.
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