Last active
August 22, 2017 14:29
-
-
Save raghavgarg1257/84a6997e0ae73425c72c4332d47fa24b to your computer and use it in GitHub Desktop.
Sample Server
This file contains hidden or 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
// app.js | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const path = require('path'); | |
const cookieParser = require('cookie-parser'); | |
const session = require('express-session'); | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.use(bodyParser.urlencoded({extended: true})); | |
app.use(cookieParser()); | |
app.use('/', require('./routes/createDisc')); | |
app.listen(3000, function() { | |
console.log('Example listening on port 3000!') | |
}) |
This file contains hidden or 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
// routes/createDisc.js | |
var express = require('express'); | |
var router = express.Router(); | |
var disc = require('../controllers/disc'); | |
router.get('/discussion/create', function (req, res, next) { | |
console.log('get /discussion/create'); | |
res.json('get all discussion'); | |
}); | |
router.post('/discussion/create', disc.createDisc); | |
module.exports = router; |
This file contains hidden or 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
// controllers/disc.js | |
exports.createDisc = function (req, res, next) { | |
console.log('post /discussion/create'); | |
res.json('create new discussion') | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment