error by node and mongodb

when I start my JS file, I get the follow error:

Charon:modules Modius$ node testfile.js 

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
ReferenceError: define is not defined
    at Object.<anonymous> (/Applications/MAMP/htdocs/spacebattles/server/modules/testfile.js:11:1)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)
Charon:modules Modius$ 

and here the js file

define(['./db_user'], function (db_user) {

    var db_user = document.createElement("db_user.js");
    var tranfer = {
        login: "test" ,
        email: "holishitumsonst.com",
        password: "123nu"
    };
    db_user.insert(transfer);

}); 

thanks for help

Answers


I think you may misunderstood the concept of node. Like Florian sayed, node.js is "only" the V8 engine withouth a browser around it. This means you have no document (no DOM at all).

To get started with node.js I recommend you to look into O'Reilly's Up and running with node.js. The modular system is explained there, too.

In Order to use MongoDB with node you have to use packages like mongoose or mongolian installed through npm. Both are explained in the book I mentioned above.


Seeing the way you've used it, it seems you're trying to use Require.js.

Node.js is not client-side code. You don't need Require.js, there is already require available.

Usage example:

// Loads the mongodb-client module in the "mongo" variable
var mongo = require('mongodb-client');

Also, there is no document available, you're not in a browser, there is no DOM either. If you want one, you can use jsdom, but I don't think this is what you want.

To sum it up: stop thinking you're in a browser. You're not. There is no document, no window, no need for custom loading, you can just program in a server environment.

I'd highly suggest you to read Node Beginner.

The aim of this document is to get you started with developing applications with Node.js, teaching you everything you need to know about "advanced" JavaScript along the way. It goes way beyond your typical "Hello World" tutorial.


Need Your Help

Accessing SOAP Service with soap4r not able to access contents of returned objects

ruby soap wsdl soap4r

So I need to access this service from my rails app. I'm using soap4r to read the WSDL and dynamically generate methods for accessing the service.

IE11 - Login button/submission buttons not working

ruby-on-rails internet-explorer-11

I am having an issue with my website. With the release of IE11, our login button on our login page simply doesn't work anymore.