Last active
April 30, 2017 18:11
-
-
Save gorkamu/956dc848586e5575e526dfe6af925e0c to your computer and use it in GitHub Desktop.
Server and get route example in NodeJS
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
'use strict' | |
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
var port = process.env.PORT || 3000; | |
// Convierte una petición recibida (POST-GET...) a objeto JSON | |
app.use(bodyParser.urlencoded({extended:false})); | |
app.use(bodyParser.json()); | |
app.get('/', function(req, res){ | |
res.status(200).send({ | |
message: 'GET Home route working fine!' | |
}); | |
}); | |
app.listen(port, function(){ | |
console.log(`Server running in http://localhost:${port}`); | |
console.log('Defined routes:'); | |
console.log(' [GET] http://localhost:3000/'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment