0

In my application i have to store data to mongodb using nodejs(npm mongodb). I have installed mongodb , nodejs and npm mongodb but the problem here is I installed them in separate folders. I am unable to organize the directory structure properly that's way I am getting errors.If you tell me the folder structure it will help me a lot.

Thanks in advance

1
  • 1
    Do you know how to make a package.json? npm init will give you a good starting point. After that, npm install is your friend. See guide. Commented Mar 11, 2013 at 5:58

2 Answers 2

3

Try mongoose - npm install mongoose, mongoose is a ODM for mongodb. API Documentation - http://mongoosejs.com/

Short example from official documentation:

var mongoose = require('mongoose');
mongoose.connect('localhost', 'test');

var schema = mongoose.Schema({ name: 'string' });
var Cat = mongoose.model('Cat', schema);

var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
  if (err) // ...
  console.log('meow');
});
Sign up to request clarification or add additional context in comments.

Comments

1

Run npm install mongodb command in your application directory. For example, nodejsapp folder is the application directory. The folder structure inside the directory will look like :

    nodejsapp
    ├───────────  node_modules <-- All the node modules installed using npm comes here --> 
    |                ├──────────── .bin
    |                ├──────────── express
    |                └──────────── mongodb
    ├───────────  app        <-- holds all our files for node components (models, routes)--> 
    ├───────────  config     <-- all our configuration will be here -->
    ├───────────  public     <-- holds all our files for our front-end application -->
    ├───────────  server.js  <-- Node configuration -->
  

The node_modules folder is created when you use npm command in the application directory.
This is a better way to organize the node packages for a project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.