Getting a HTTP 404 error when doing app.post in Node.js -
i newbie node.js trying learn through tutorials found online using netbeans.
when do: http://localhost:9080/ see date , color expected. when try http://localhost:9080/add, see app.post part, http 404 error.
could let me know doing wrong.
thanks in advance,
ind.ejs
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <h1> app </h1> <%= new date() %> color is: <%= test %> </body> </html>
index.js:
'use strict'; module.exports = require('./lib/express'); var http = require('http'); var express = require('express'); var path = require('path'); var ejs = require('ejs'); var app = express(); var tropo_webapi = require('tropo-webapi'); var bodyparser = require('body-parser'); var test; var app = express(); //app.use(bodyparser()); app.set('view engine','ejs'); app.set('views', path.join(__dirname,'views')); app.get('/',function(req,res){ var test = 'red'; console.log('test in :' + test); res.render('ind.ejs',{test:test}); }); app.post('/add',function(req,res){ test = 'blue'; console.log('test in post :' + test); res.render('ind.ejs',{test:test}); }); app.listen(9080, function(){ console.log('ready on port 9080'); });
app.get
'get' http verb, used default. app.post
triggered 'post' http verb, can done using forms:
<form action="/add" method="post"><button type="submit">go</button></form>
Comments
Post a Comment