node.js , mongodb, mongoose, html how can i insert data(in index.html)? node.js , mongodb, mongoose, html how can i insert data(in index.html)? mongoose mongoose

node.js , mongodb, mongoose, html how can i insert data(in index.html)?


There are a multitude a possibilities. What I usually do is create an express server and attach the routes to special functions in express.

//your modulesvar express = require('express'),    app = express(),    mongoose = require('mongoose');//connect mongoSchema = mongoose.Schema;mongoose.connect('mongodb://localhost/mydatabase');//schemavar UserSchema = new Schema({ user_id : String, email : String, base_location : Number, user_type : String, number_of_event : Number});mongoose.model('User', UserSchema);var User = mongoose.model('User');var user  =new Userapp.post('/api/users', function (req, res){  //do your stuff});app.listen(80);

You then will need to run the above script (lets call it app.js) with

node app.js

If the code above is sane, this will run the server. When you connect to the server with the app then you will receive a connection. You should also look up some docs on socketIO.