Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Last active April 30, 2017 18:11
Show Gist options
  • Save gorkamu/956dc848586e5575e526dfe6af925e0c to your computer and use it in GitHub Desktop.
Save gorkamu/956dc848586e5575e526dfe6af925e0c to your computer and use it in GitHub Desktop.
Server and get route example in NodeJS
'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