Dman Dman - 1 year ago 96
Javascript Question

I have just started on MEAN stack. I was trying to store my form submit data to mongo database but i have been unable to do so. Help Appreciated

var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var Schema = new mongoose.Schema({
uname: String,
upno: Number,
umno: Number,
ul1: String,
l2: String,
ul3: String
var user = mongoose.model('emp', Schema);
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.get('/', function (req, res) {
res.sendFile(__dirname + "/" + "assign.html");
});'/', function (req, res) {
new user({
uname: req.body.username,
upno: req.body.uphno,
umno: req.body.umbno,
ul1: req.body.l1,
ul2: req.body.l2,
ul3: req.body.l3
}).save(function (err, doc) {
if (err) res.json(err);
else res.send('Successfully inserted!');
app.listen(8086, function () {
console.log('Server running at');

I am getting this error :-

C:\Users\hp pc\WebstormProjects\MyForm2\node_modules\mongodb\lib\server.js:242
process.nextTick(function() { throw err; })
Error: connect ECONNREFUSED
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1062:14)

Bun Bun
Answer Source

The error message indicate that you didn't start Mongo server. Make sure you start it first by running mongod in your command prompt or terminal.