Skip to content

Instantly share code, notes, and snippets.

@huangsam
Last active March 29, 2018 17:18
Show Gist options
  • Save huangsam/173a16b668f2b59b005719dcb2d06cc5 to your computer and use it in GitHub Desktop.
Save huangsam/173a16b668f2b59b005719dcb2d06cc5 to your computer and use it in GitHub Desktop.
Simple Express app with router endpoint
var express = require('express')
var router = express.Router()
// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
console.log('Time: ', Date.now())
next()
})
// define the home page route
router.get('/', function (req, res) {
res.send('Birds home page')
})
// define the about route
router.get('/about', function (req, res) {
res.send('About birds')
})
module.exports = router
var birds = require('./birds')
var express = require('express')
var app = express()
app.use('/birds', birds)
app.listen(3000, () => console.log('Example app started'))
{
"name": "express-app",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"express": "^4.16.3"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
@huangsam
Copy link
Author

And if Express is too minimalistic, then Meteor is another option: https://www.meteor.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment