Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
70
rated 0 times [  71] [ 1]  / answers: 1 / hits: 27042  / 9 Years ago, sun, january 3, 2016, 12:00:00

I have seen other questions with the same error, but none of the answers seem to work.



<!DOCTYPE html>
<html>
<body>

<form action=http://127.0.0.1:8080/del method=post>
First name: <input type=text name=fname><br>
Last name: <input type=text name=lname><br>
<input type=submit value=Submit>
</form>

<p>Click on the submit button, and the input will be sent to a page on the server called http://127.0.0.1:8080/del.</p>

</body>
</html>


server.js



var express=require('express');
var body_parser=require('body-parser');
var request = require('request').defaults({json:true});
var app=express();
var del=require('./del');
app.post('./del',del.test);
var server = app.listen(8080,function(){
var host=127.0.0.1;
var port=8080;
console.log(App is listening at http://%s:%sn,host,port);
});


del.js



module.exports={
test: function(){
console.log(Hello world.);
}
};


Each time, when I submit the form, it shows




Cannot POST /del



More From » node.js

 Answers
20

In your server.js change this line:



app.post('./del',del.test);


to this:



app.post('/del',del.test);


then you have correct router.



And your del.js change to this:



module.exports={
test: function(req, res){
console.log(Hello world.);
res.status(200).end();
}
};


because router function should return response.


[#63864] Wednesday, December 30, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
michelecarissab

Total Points: 730
Total Questions: 97
Total Answers: 110

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
;