Last active
August 29, 2015 14:03
-
-
Save ctmay4/acd1ffa4a7c006b5adc4 to your computer and use it in GitHub Desktop.
Simple node 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
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']); | |
}; |
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
{ | |
"name": "express-testing", | |
"main": "server.js", | |
"dependencies": { | |
"body-parser": "^1.4.3", | |
"express": "^4.5.1", | |
"mongoose": "^3.8.12", | |
"compression": "^1.0.8" | |
} | |
} |
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basic Node/Express Server
Make sure node and npm are installed. If
grunt
is not installed, install it now.Install dependencies
Run server