1

Background Information

I'm trying to follow this tutorial : http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/

I have a mongo database running on another linux box...and fwiw, I know it's working because I have a php application that can connect and query.

I'm not using mongoose... but monk, since this is what the tutorial calls for.

Here's what my package.json file looks like:

{
  "name": "testapp",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.13.2",
    "cookie-parser": "~1.3.5",
    "debug": "~2.2.0",
    "express": "~4.13.1",
    "mongodb": "^1.4.4",
    "monk": "^1.0.1",
    "morgan": "~1.6.1",
    "pug": "^2.0.0-beta4",
    "serve-favicon": "~2.3.0"
  }
}

~

Problem

When I try to run the test node application, I'm getting the following error message:

me@mydevbox:/var/www/html/node/testapp$ node app.js 
{ Error: Cannot find module '../build/Release/bson'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/var/www/html/node/testapp/node_modules/mongodb/node_modules/bson/ext/index.js:15:10)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version

This is what the index.js file looks like:

  3 try {
  4         // Load the precompiled win32 binary
  5         if(process.platform == "win32" && process.arch == "x64") {
  6           bson = require('./win32/x64/bson');  
  7         } else if(process.platform == "win32" && process.arch == "ia32") {
  8           bson = require('./win32/ia32/bson');
  9         } else { 
 10           bson = require('../build/Release/bson');
 11         }     
 12 } catch(err) {
 13         // Attempt to load the release bson version
 14         try {
 15                 bson = require('../build/Release/bson');
 16         } catch (err) {
 17                 console.dir(err)
 18                 console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
 19                 bson = require('../lib/bson/bson');
 20         }
 21 }

What I've Tried:

Based on other posts on stackoverflow.com, I tried to change line 15 to look like this:

15                 bson = require('bson');

I've also tried running the command:

 sudo npm install bson 

But that didn't resolve the problem.

In case it helps, I did a search for "bson" on my box and came up with these results: http://pastebin.com/WKQygGak

System Information

Ubuntu 15.10

EDIT 1

me@mydevbox:/var/www/html/node/testapp$ sudo apt-get install gcc make build-essential
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version.
gcc is already the newest version.
make is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

And then I ran the following commands:

http://pastebin.com/MDerppWB

There's seems to have been an error on line 10 but I'm not sure how to correct it.

EDIT 2

This is what I currently have in my npm config:

me@mydevbox:/var/www/html/node/testapp$ npm config list
; cli configs
user-agent = "npm/3.10.3 node/v6.3.1 linux x64"

; userconfig /home/me/.npmrc
https-proxy = "http://10.1.1.11:8080/"
proxy = "http://10.1.1.11:8080/"
python = "python2.7"

; globalconfig /usr/etc/npmrc

; node bin location = /usr/bin/nodejs
; cwd = /var/www/html/node/testapp
; HOME = /home/me
; "npm config ls -l" to show all defaults.

me@mydevbox:/var/www/html/node/testapp$ 

Also as a test I tried to just to "sudo npm install bson" and it fails with the same errors that I see in the pastebin I posted.

Happydevdays
  • 1,982
  • 5
  • 31
  • 57

1 Answers1

1

You probably need build essentials, because there is some c++ dependency going on here. Please refer to the following answer or just do the following.

sudo apt-get install gcc make build-essential

rm -rf node_modules
npm cache clean
npm install

Edit:

This could also be a python issue. Make sure python 2.7 is installed for ubuntu, in your PATH, and then set up npm to look for python:

npm config set python python2.7

Others having the same issue as you found this to be a solution. Python looks to be the next step since you've established that you have build-essentials.

Edit 2:

Side note.. I know you're following a tutorial.. but for future reference I strongly recommend using the native mongo driver. It's faster than ORM's like mongoose, and not difficult to use (not saying mongoose is difficult to use, but just not as flexible or performant).

Community
  • 1
  • 1
Patrick Motard
  • 2,650
  • 2
  • 14
  • 23