← helloexpress

post request to users route /users is where the signup form is located get the post request, the informatiuon is not passed in as part of the route but part of the body.

49e470c0a69c76fa792d61cd4359f5204d104ba2 · ovidiucs · Apr 16, 2014 04:08

+5 −2 · 1 file changed

  • app.js +5 −2
diff --git a/app.js b/app.js
index daa37df..12a18f1 100644
--- a/app.js
+++ b/app.js
@@ -6,8 +6,8 @@ var express = require('express')
 	,http		= require('http');
 
 var app = express();
-
-// all environments
+// parse body of req
+app.use(express.bodyParser());
 app.set('port', process.env.PORT || 3000);
 // get
 // reads data
@@ -33,6 +33,9 @@ app.get('/users/:userId', function(req,res) {
 
 // post
 // create data
+app.post("/users", function(req,res) {
+	res.send("Creating a new user with the name " + req.body.username + ".");
+});
 
 // delete
 // delete data