I'm currently learning node.js (Windows) and I have to test fake requests. I've been searching, saw some possible solutions but I can't implement them. So far I can only start the server with get, post, put and delete methods, but not with 'foo' or something similar
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var fs = require("fs");
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.use(express.static('public'));
app.get('/index.html', function (req, res) {
res.sendFile( __dirname + "/" + "index.html" );
})
app.post('/process_post', urlencodedParser, function (req, res) {
response = {
fname:req.body.fname,
surname:req.body.surname,
age:req.body.age,
phone:req.body.phone,
city:req.body.phone,
email:req.body.email,
country:req.body.country,
postal_code:req.body.postal_code,
password:req.body.password
};
console.log(response);
res.end(JSON.stringify(response));
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Listening at http://%s:%s", host, port)
})
If I start the server with other method I get an error like "app.foo is not a function" in the console. Can someone help me out?
via glassraven
No comments:
Post a Comment