-2

I was trying to install mongojs by this command: npm install mongojs

but there are coming so many errors .

https://www.youtube.com/watch?v=763oFTm4pnU

So,i restarted my pc and tried installing again but same errors are coming . but i still tried to retrieve data from mongodb through server because there are somethings that are still installed after so many errors. i have written this code in my server.js file-

var express= require('express');
var app=express();
var mongojs = require('mongojs');
var db = mongojs('contactlist',['contactlist']);


app.use(express.static(__dirname + "/public"));

app.get('/contactlist',function (req,res) {
    console.log("i receive a get request");

    db.contactlist.find(function (err,docs){
        console.log(docs);
        console.log("in daatbase");
        res.json(docs);
    });
});

app.listen(3000);
console.log("Server running on port 3000");

I have recorded the errors ..please come up with solutions.

please watch thsi video which contains all my errors..

https://www.youtube.com/watch?v=763oFTm4pnU

In this video there are errors that are coming while installing MongoJs.

Thank You.

2 Answers2

0

Yo have firstly update your node using:

1) Clear NPM's cache:

sudo npm cache clean -f

2) Install a little helper called 'n'

sudo npm install -g n

3) Install latest stable NodeJS version

sudo n stable

After that install mongojs:

sudo npm install mongojs

Donot forget to use sudo if you are using Linux platform

Karan
  • 1,048
  • 2
  • 20
  • 38
0

Have you tried installing it using a package.json file?

1) You should create a package json file in this format:

{
  "name": "Your App Name",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "dependencies": {
    "body-parser": "^1.10.2",
    "express": "^4.11.1",
    "mongojs": "^2.4.1"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "forever -w server.js"
  },
  "repository": {
    "type": "git",
    "url": "Your github url"
  },
  "author": "",
  "license": "ISC"
}

2) Then make sure mongojs is under the dependencies as:

"mongojs": "^2.4.1"

3) After adding mongojs to the dependencies file, navigate to the project directory in your terminal and type in:

npm install

This will create a node_modules folder in your project directory containing all the necessary packages.

NC11
  • 26
  • 1
  • 7