A
A
artem201520002015-02-10 16:56:30
MongoDB
artem20152000, 2015-02-10 16:56:30

Why does it throw an error when including (or adding) in node.js?

That's my node.js code

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var MongoClient = require('mongodb').MongoClient;
app.set('view engine', 'ejs');
app.use("/stylesheets",express.static(__dirname + "/stylesheets"));
app.use(bodyParser());
//db
MongoClient.connect("mongodb://localhost:27017/blog", function(err, db) {
  if(!err) {
    console.log("We are connected");
  }
});
app.get('/', function(req, res) {
  res.render('index')
});
app.post('/send_post', function(req, res) {
  var name = req.body.name;
  var post_name = req.body.post_name;
  var post_text = req.body.post_text;
  var collection = MongoClient.collection('users');
  collection.insert({name: "Artem"});
  res.send("Name: " + name + ", Name of the post: " + post_name + ", Text of the post:" + post_text);
  console.log("Name: " + name + ", Name of the post: " + post_name + ", Text of the post:" + post_text);
});
app.listen(3000);

That's an error in my console
D:\programms\node>node D:\programms\website\app.js
body-parser deprecated bodyParser: use individual json/urlencoded middlewares ..
\website\app.js:8:9
body- parser deprecated undefined extended: provide extended option ..\website\no
de_modules\body-parser\index.js:85:29
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server. listen (net.js:1138:5)
at Function.app.listen (D:\programms\website\node_modules\express\lib\
application.js:556:24)
at Object. (D:\programms\website\app.js:34:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module. load (module.js:356:32)
at Function.Module._load (module.js:312:12)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-02-10
@MarcusAurelius

Someone is already sitting on port 3000, it is clearly written EADDRINUSE, make app.listen(3030);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question