Answer the question
In order to leave comments, you need to log in
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);
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question