javascript - NodeJS + ExpressJS: What is routes/index.js and its purpose? -
what purpose of file?
is 'all' , post calls instantiated?
if so, wouldn't huge file when working large scale projects?
i've tried calling post, /authenticatelogin, file other routes/index.js, fails work, resulting in 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 works when put in 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')
that's load framework , define routes.
Comments
Post a Comment