1

I've got a really simple server I'm trying to setup which uses Mongoose (to connect to MongoDB) and Express (to serve up files). The app.js file looks like the following:

var express = require('express');
var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/test');

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (callback) {
  console.log("MongoDB connection is open.");
});

// Mongoose Schema definition
var Schema = mongoose.Schema;
var LocationSchema = new Schema({
    //insert schema definition here
});

// Mongoose Model definition
var LocationsCollection = mongoose.model('locations', LocationSchema);
// Bootstrap express
var app = express();
// URL management
app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

// Start the server
app.listen(3000);

So, I make sure I start the mongod.exe file (and it's running in the background). Then, I open another command prompt, cd to my working directory and launch my server code using -node app.js. The code starts and indeed I see the message saying that the "MongoDB connection is open". So, the mongoose connection seems to work fine. But, then when I open a browser and type in the URL: http://127.0.0.1:3000 I immediately get an error saying:

Error: ENOENT, stat 'D:\Users\myname\Desktop\Server\index.html'

Now, I know for a fact that the index.html file is indeed in that folder (which is the same folder as my app.js)... so I don't know why I'm getting this error. I've seen other threads saying I need to create an npm folder in my roaming directory... but it's already there. It seems to always be 'read-only' even if I uncheck that box and apply the settings... but, I don't know what could be wrong. I'm using the latest versions of node and mongodb. The issue clearly seems to be occurring when the express server tries to serve up the index.html file... but I can't figure out where the error is occurring. Any thoughts?

andyopayne
  • 1,348
  • 3
  • 24
  • 49
  • 1
    Check out [this answer](http://stackoverflow.com/a/25095327/1024766) -- this error is caused by a problem with node on Windows. – soulprovidr Feb 05 '15 at 20:30
  • 1
    Yes, I had seen that thread. Looking through the suggestions... I've tried to downgrade node.js to a stable build (http://blog.nodejs.org/2014/06/16/node-v0-10-29-stable/) and I installed npm using a global variable `npm install npm -g`... I also installed the mongoose and express node modules in my folder using the global variable... but it still fails. I'm using Windows 8.1... is this something that is completely unfixable? – andyopayne Feb 05 '15 at 20:46
  • 1
    Have you tried [this](https://github.com/npm/npm/wiki/Troubleshooting#error-enoent-stat-cusersuserappdataroamingnpm-on-windows-7)? "The workaround is to ensure that C:\Users\\AppData\Roaming\npm exists and is writable with your normal user account." – soulprovidr Feb 05 '15 at 20:47

0 Answers0