Simple App Using Bootstrap, AngularJS, NodeJS and MongoDB.

A simple try using Node and Mongo to develop a Finance APP. Posted in Git hub link HERE.

  • Frontend – HTML, Bootstrap.
  • Framework – AngularJS.
  • Backend – NodeJS.
  • Database – MongoDB.

MongoDB CRUD Using Mongoose

Initialize Mongoose and Schema

var mongoose = require('mongoose');
mongoose.connect('mongodb://YOURVALUES.mongolab.com:11111/NAME');
var schema = new mongoose.Schema({ name: 'string', account: 'string', date: 'string' });
var accountz = mongoose.model('accountz', schema);

Create

   var small = new accountz({
        name: "SAMZ",
        account: "Monthly",
        date: "29/12/2015"
    });
    small.save(function (err) {
        if (err){
            console.log("Error in Save");
        }else{
            console.log("Save Sucessfully");
        }
    });

Read

   accountz.find().exec(function(err, data){
        if (err){
            console.log("Error in Reading");
        }else{
            console.log("The value = " + data);
        }
    });

Update

   accountz.findOne({ "_id": "0023"}, function (err, doc){
        doc.name = editObj.name;
        doc.account = editObj.account;
        doc.date = editObj.date;
        doc.save(function (err) {
            if (err){
                console.log("Error in Updating");
            }else{
                console.log("Updated Sucessfully");
            }
        });
    });

Delete

    accountz.remove({ "_id": "0023"}).exec(function(err, data){
        if (err){
            console.log("Error in Deleting");
        }else{
            console.log("Deleting Sucessfully");
        }
    });

You can refer to my github project Explore Here .

Get Users of a Room in NodeJs-SocketIO

In a chat using NodeJs / SocketIO, to get the all user using a room can be found by following code,

function get_users_by_room(nsp, room) {
  var users = []
  for (var id in io.of(nsp).adapter.rooms[room]) {
    users.push(io.of(nsp).adapter.nsp.connected[id]);
  };
  var roomUsers = [];
  users.forEach(function(elem){
      roomUsers.push({
          id : elem.id,
          name : elem.name,
          roomName : elem.rName
      });
  });
  return roomUsers;
};

This can be used to find the online users.

onclick in jsFiddle

you have wrapped the function in body – onLoad, just change it into “No wrap – in< head>”,  change it in javascript setting.
see this fiddle:link

HTML

<input type="submit" id="hit" value="Search" onclick="myFunction()" class="btn">

JS


function myFunction() {
    alert("I am an alert box!");
        }
};

How to generate random number with in a range,count and also having the exist number?

My Experience

Problem:

Generate Random Number Arr within a range,count and also handle exist number: javascript

Fix:

View original post

Display image Using input[file]

Displaying Local Images


function readURL(input) {
  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#ImgId')
        .attr('src', e.target.result)
        .width(350);
    };

    reader.readAsDataURL(input.files[0]);
  }
}

Demo