Skip to content

Instantly share code, notes, and snippets.

@ctmay4
Last active August 29, 2015 14:03
Show Gist options
  • Save ctmay4/acd1ffa4a7c006b5adc4 to your computer and use it in GitHub Desktop.
Save ctmay4/acd1ffa4a7c006b5adc4 to your computer and use it in GitHub Desktop.
Simple node server
module.exports = function(grunt) {
grunt.initConfig({
// configure nodemon
nodemon: {
dev: {
script: 'server.js'
}
}
});
// load nodemon
grunt.loadNpmTasks('grunt-nodemon');
// register the nodemon task when we run grunt
grunt.registerTask('default', ['nodemon']);
};
{
"name": "express-testing",
"main": "server.js",
"dependencies": {
"body-parser": "^1.4.3",
"express": "^4.5.1",
"mongoose": "^3.8.12",
"compression": "^1.0.8"
}
}
var express = require('express')
var compression = require('compression')
var app = express()
var bodyParser = require('body-parser')
app.use(compression()) // use gzip encoding
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
app.use(bodyParser.json()) // parse application/json
var port = process.env.PORT || 8080
// serve static HTML from public directory
app.use(express.static(__dirname + "/public"))
// configure router
var router = express.Router()
router.get('/', function(req, res) {
res.json({ message: 'APIs go here!' })
})
// all of our API routes will be prefixed with /api
app.use('/api', router)
app.listen(port)
console.log('Listening on port ' + port)
@ctmay4
Copy link
Author

ctmay4 commented Jul 10, 2014

Basic Node/Express Server

Make sure node and npm are installed. If grunt is not installed, install it now.

$ npm install -g grunt-cli

Install dependencies

$ npm install

Run server

$ grunt

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