What is the purpose of this file?
Is this where 'all' the get and post calls get instantiated?
If so, wouldn't this be a very huge file when working with large scale projects?
I've tried calling a post, /authenticateLogin, from another file other than routes/index.js, but it fails to work, resulting in a 404 error.
routes/login.js
var express = require('express');
var router = express.Router();
router.get('/', function(req, res) {
res.render('login');
});
router.post('/authenticateLogin', function(req, res){
console.log("Authenticating 2!");
res.send('number two!');
});
module.exports = router;
But it works perfectly when I put it in the index.js file.
routes/index.js
var express = require('express');
var router = express.Router();
router.get('/', function(req, res) {
res.render('index', { title: 'Home' });
});
router.post('/authenticateLogin', function(req, res){
console.log("Authenticating 1!");
res.send('number one!');
});
module.exports = router;
views/login.jade
extends layout
block content
h1 Login
form(method='post' action='/authenticateLogin')
input(type='text' placeholder='username' name='username')
input(type='password' placeholder='password' name='password')
input(type='submit')