Comments (6)
If anyone encounters this problem, try adding .json()
after using body-parser with express. For example if I require body-parser as "parser" I would write app.use(parser.json())
. I recommend this before removing it and updating express
from blog.
var express=require('express');
var path=require('path');
var app=express();
var morgan=require('morgan');
var mongoose=require("mongoose");
var personal=require("./models/reg_personaldb");
var bodyParser=require("body-parser");
app.set()
app.use(morgan('dev'));
app.use('/assets',express.static('assets'));
app.use('/countryplugin',express.static('countryplugin'));
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
mongoose.connect('mongodb://localhost:27017/practicum',function(err){
if(err){
console.log("Not Successful"+err);
}else{
console.log("DB Successful");
}
});
app.post('/personal',bodyParser,function(req,resp){
var personaldata=new personal({
fullName:req.body.fullname,
address:req.body.address,
country:req.body.country,
gender:req.body.gender,
dob:req.body.dob,
branch:req.body.branch,
email:req.body.email,
phone:req.body.phonenumber
});
personaldata.save(function(err){
if(err){
console.log(personaldata);
console.log("Username Already exists"+err);
}else{
console.log(personaldata);
console.log("user created");
resp.send("user created");
}
});
});
app.get('/home',function(req,resp){
resp.sendFile('Home.html',{root: path.join(__dirname,'')});
})
app.get('/loginuser',function(req,resp){
resp.sendFile('Login.html',{root: path.join(__dirname,'')});
})
app.get('/loginphone',function(req,resp){
resp.sendFile('loginwithphone.html',{root: path.join(__dirname,'')});
})
app.get('/register',function(req,resp){
resp.sendFile('register.html',{root:path.join(__dirname,'')});
})
app.post('/registereducation',function(req,resp){
resp.sendFile('registereducation.html',{root:path.join(__dirname,'')});
})
var server=app.listen(1337,function(){
console.log("Listening at port 1337");
});
this is the code which we have written can you please fix this problem.
from blog.
Not working for me either. =(
I'm getting these warnings in the console as well:
body-parser deprecated bodyParser: use individual json/urlencoded middlewares node_modules/simplehttpserver/node_modules/express/lib/router/layer.js:95:5
express deprecated req.host: Use req.hostname instead node_modules/simplehttpserver/node_modules/body-parser/index.js:100:29
body-parser deprecated undefined extended: provide extended option node_modules/simplehttpserver/node_modules/body-parser/index.js:105:29
from blog.
Fixed!
from blog.
how can you fixed this problem
from blog.
Update express
and remove references to bodyparser
from your code.
from blog.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.