FAQ Database Discussion Community


Mongoose 'populate' not populating

mongoose,mean-stack,mongoose-populate
I am building a fairly simple application on the MEAN stack and I am really out of my depth, especially when it comes to mongoose. I have found the mongoose documentation very difficult to wrap my head around and cannot find answers anywhere else. My issue is this: I have...

Is express similar to grunt? what is the difference? what are the advantages of express over grunt?

node.js,express,gruntjs,mean-stack
I've been working on node,grunt,bower and yeoman from couple of months. I came across MEAN stack applications, in which expressjs is providing the server environment(my understanding). Are both grunt and express similar? Requesting for some helpful link on express and MEAN stack. ...

Speeding up AWS EC2 using MEAN

performance,amazon-web-services,amazon-ec2,varnish,mean-stack
I recently opened a AWS server with a t1.micro EC2 instance. I have MEAN, forever, nginx, and varnish running but it's still extremely slow to access the website. Over the EC2 server my mean app is super slow. When I'm in localhost:3000, it's really fast. Any ideas?...

Update the todo list without refreshing the page in express nodejs app

javascript,node.js,asynchronous,express,mean-stack
I am a newbee to the express nodejs applications. I want to make a todo list. This is how it looks so far. My question is when I add a todo, it takes some time to show the change since it reloads the page. How can I see the change...

Call ExpressJS as Rest API for HTML page

html,node.js,express,mean-stack
I am creating web page with a button to load data from the server using Rest API build through ExpressJS, NodeJs. var express=require('express'); var mysql=require('mysql'); var app=express(); var server=app.listen(3000,function(){ console.log("Express is running on port 3000"); }); app.get('/search',function(req,res){ var mysql=require('mysql'); var connection = mysql.createConnection({ connectionLimit : 100, //important host : 'localhost',...

Redirect to original request after authentication, Angular-Fullstack?

angularjs,authentication,redirect,mean-stack,angular-fullstack
I am using the angular-fullstack (https://github.com/DaftMonk/generator-angular-fullstack) from the yeoman generator for the MEAN stack. I am new to most of these technologies and am just beginning to wrap my head around how the pieces fit together. I am trying to figure out how to redirect a freshly authenticated user to...

MEAN stack: sending a string to client through a web service, can't access my string

angularjs,web-services,parameter-passing,mean-stack
Like the title says, I need a web service to send a string back to the client. I'll give you a little code example. This is my route file: /*log.js*/ var express = require('express'); var router = express.Router(); router.get('/myRoute', function(req, res){ var greeting = "Hello there!"; res.json({"myMsg" : greetings}); }...

Need help resolving angular routing throwing a 500 error

angularjs,express,angular-ui-router,mean-stack
I cannot figure out how to resolve my 500 issue. I do not know if i need to make a change in express or angular. Here is my main.js public Any help is appreciated var app = angular.module('myApp', ['ui.router'], function ($interpolateProvider) { $interpolateProvider.startSymbol('[['); $interpolateProvider.endSymbol(']]'); }); app.config(function($stateProvider,$urlRouterProvider,$locationProvider){ // $locationProvider.hashPrefix('!'); // $urlRouterProvider.otherwise('/home');...

What is the difference between install MongoDB standalone or through npm

node.js,mongodb,npm,mean-stack,meanjs
I am pretty new for MEAN and just went some round trip (half day install and uninstall MEAN and everything with it?) and do not want to do it again. So I ask everyone here for help. The MongoDB I installed on Windows8 is working and already built as a...

Query a $resource in AngularJS with params

angularjs,node.js,mean-stack
I have a api that displays a list of transactions between 2 dates. I would like to access that data as an angular resource. When I try what happens is I get a bunch of GET /trans/12-01-2014/12-02-2014 200 1690ms - 953.2kb GET /trans 404 1ms GET /trans 404 1ms DELETE...

Getting 404 error on API PUT call with route param

angularjs,node.js,express,mean-stack,angular-http
This is the API url I'm trying to hit in my Express app: // Dashboard API to update account app.post('/api/accounts/:id', accountsController.update); My full accounts module with Accounts factory, then specific descriptions below that: (function() { var app = angular.module('app-accounts', ['ngAnimate', 'ngResource', 'account-directives']) .controller('AcctCtrl', ['$scope', '$resource', 'Accounts', function($scope, $resource, Accounts) {...

Multer module won't start

node.js,express,mean-stack,multer
I'm writing a web app using the MEAN stack. I installed multer via npm like so: sudo npm install -g multer and I require it in one of my routes files: var multer = require("multer"); I'm using nodemon and it throws the following error every time it restarts since I've...

Meanjs How to link one query to a different controller

angularjs,model,mean-stack,meanjs
I have one crud-module called article and anther one called Devices. I would like the data from article crud-module to be also in Device article. Does anyone have an idea how to implement this? devicesApp.controller('DevicesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Devices','$modal', '$log', function($scope, $stateParams, $location, Authentication, Devices, $modal, $log) { $scope.authentication...

MongoDB. How to update json property inside an array

json,node.js,mongodb,mean-stack
I'm using the Mean stack. I'm uncomfortably new to this and have got myself in a pickle. I've seen examples of updating records using set or push but because I'm trying to update one json object within a json object within an array of json objects I'm having trouble. Consider...

how to a value from node/express app to an AngularJS controller

javascript,angularjs,node.js,mean-stack,meanjs
I'm developing an app based on mean.js boiler plate. In one of my Angular controllers, I need to "know" whether the app is running in dev, test, or prod. When the hosting Node app starts, this is indicated via the NODE_ENV environment variable, so Node knows where its running. How...

How to use MongoDB findOne() with mongoose

node.js,mongodb,mongoose,mean-stack
I'm having troubles using the MongoDB findOne() function together with mongoose. controller exports.show = function (req, res) { Fahrt.load(req.params.fahrtenId, function (err, fahrt) { res.jsonp(fahrt); }); }; model FahrtSchema.statics = { load: function (id, cb) { this.findOne({ _id: id } ).exec(cb); }}; route router.get('/:fahrtId', fahrtenController.show); app.js app.use('/fahrten', fahrten); When I use...

how to stop using livereload.js in my MEAN app

node.js,mean-stack,meanjs
I have moved my dev MEAN app from my laptop onto Azure. I have set off of grunt's livereload flags to false, but, livereload.js is still being loaded, and its absolutelly killing me! It take like 30 seconds(!) waiting for livereload.js Is there a way to get rid of it...

Documents “disappearing” from mongodb collection after node loading routine is finished

javascript,node.js,mongodb,mean-stack
Being new to mongodb and node, this particular issue is just driving me crazy: I have written a small module, which reads an .csv file, makes it into a JSON array, and loads it into a mongodb collection one record at a time in a loop. As I run this...

Error after installing Node.js in Linux

node.js,ubuntu-14.04,mean-stack
I am getting following error after typing $ node - version in My Linux Machine: Error: unrecognized flag - Try --help for options module.js:340 throw err; ^ Error: Cannot find module '/home/ojas/version' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:935:3 I have used following...

Passing variables into a query in mongoose in the first argument

node.js,mongodb,mean-stack
I am using MEAN stack, i have an entry like this in my mongodb { "_id" : ObjectId("5577467683f4716018db19ed"), "requestMatrix" : { "1698005072" : { "rideId" : "641719948", "status" :"accepted" },"1698005073" : { "rideId" : "641719545", "status" :"rejected" } }, "partners":[ { "customerNumber" : 1698005072 }, { "customerNumber" : 1698072688 }...

how to properly send and receive form data in an angular/node application

angularjs,node.js,express,mean-stack,meanjs
I'm writing an app based on mean.js boiler plate I have a form in my angular view, which need to send some formData: <form name="form" ng-submit="postUpdate()"> <div class="form-group"> <fieldset> <legend><strong>Salesforce Opportunity</strong> </legend> <div class="col-sm-6"> <label for="opportunityId">Opportunity ID</label> <input id="kw" name="opportunityId" type="text" placeholder="kw" class="form-control" ng-model="kwRequired"/> ...... In my angular controller, I...

What is the role of exec() and next() call in cascade delete in mongoose middleware?

express,mongoose,mean-stack,meanjs
I'm new to using mongoose middleware and don't know if I'm following it well. Here is the purpose. After saving department, I want to populate university and save departmentId inside university object. DepartmentSchema.post('save', function(next) { var departmentId = this._id; University.findOne({ _id: this.university }, function(err, university) { if (!university.departments) { university.departments...

Token with angularjs

javascript,angularjs,node.js,mean-stack
My current problem, is how to redirect signup route to homepage route with the token. The backend of this route does create the token, but for the frontend I couldn't figure out of how to do it. .controller('UserCreateController', function(User, $location, $localStorage) { var vm = this; // function to create...

dd-collapse-text with emoji filter

javascript,angularjs,angularjs-directive,mean-stack,angularjs-filter
I'm using dd-collapse-text directive to collapse descriptions in my webpage and works fine. <span data-dd-collapse-text="350" data-ng-bind-html="description"></span> Result example (not for 350 characters): Lorem Ipsum ... (more) But, now I want to use it for the comments; and they are filtered with emoji filter for the icons. And this is not...

How can I prevent OpsWorks Deployment from defaulting to deploying to my Custom Layer?

amazon-web-services,mean-stack,aws-opsworks
I currently have a relatively simple OpsWorks MEAN stack configuration, consisting of two layers. One layer is the Node.js App Server layer, and the other layer is a Custom MongoDB layer. (As a side note, I hope one day Amazon will provide a Mongo store for OpsWorks, but until then,...

Angular + socketio don't work?

angularjs,node.js,socket.io,mean-stack
Currently I'm trying to implement a real-time content with socket.io and angular.js, and as far as I concern I did everything correct, but the real-time doesnt work. Maybe I miss out anything important. I will write a scenario of how its supposed to work. Basically a user write a content...

Having trouble on rendering data to angular

javascript,angularjs,node.js,mean-stack
Currently I'm trying to render a specific data on angular with node/express as the backend. What I'm trying to achieve is whenever a user clicks a specific story, it will link to that specific story page that belongs to a user who created the story. api.js apiRouter.get('/:user_name/:story_id', function(req, res) {...

How to implement cascade insert with MEAN/MongoDB?

mongodb,express,mongoose,mean-stack,meanjs
I'm trying to implement cascade insert for objects with 1 to many relationship in Mongoose/MongoDB and struggling to implement it. In this case, university has one to many relationship with departments. Here is my university object. var UniversitySchema = new Schema({ name: { type: String, default: '', trim: true },...

What does a MEAN (stack) Node.js app directory look like in comparison to a rails (stack) directory?

ruby-on-rails,node.js,mean-stack
This is my first time looking at a Node stack and I'm a little confused about some basic stuff since I learned web development using Ruby on Rails. I understand what a rails directory looks like. demo/ ..../app ......../assets *Javascript, CSS, images, etc* ......../controller *Connect the model with the view*...

REST API. AngularJS to Express. Error 500;

angularjs,express,mean-stack
Please help me to figure out the logic behind Express REST API. I am moving my self-education from pure AngularJS to MEAN stack, so please bear with me. I have the following angular controller, which takes data from my contact form and put it into formData object. app.controller('ContactCtrl', ['$scope', '$http',...

Mongo giving dup key error for fields with unique: false

javascript,node.js,mongodb,mean-stack
UPDATE:Thanks JohnnyHK for your answer, my issue has been resolved! Initial Question: Any ideas why I am getting the below error message? Note that everything before the "We are connected" line prints out even when the program runs properly. DEBUG=cfcwebportal:* ./bin/www [Error: /home/ben/Code For Chicago/cfcwebportal/node_modules /mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header] js-bson:...

Differences betwen findById and load?

mongodb,mongoose,mean-stack
What's the main difference between FindById(id,callBack) and Load(id,callback) ? More details: I'm new to MEAN stack web development, so i'm just playing with Mean.io: This code is generated by Mean.io(controllers/article.js): Article.load(id, function(err, article) { if (err) return next(err); if (!article) return next(new Error('Failed to load article ' + id)); req.article...

logging message on chrome console in expressjs - MEAN Stack

javascript,google-chrome,express,mean-stack
I have a created routes and calling some functions in expressjs. This function is properly getting executing and retuning data. exports.index = function (req, res) { Data.find({ parent: null }, function (err, employee) { if (err) { return handleError(res, err); } return res.status(200).json(employee); }); }; I want to log some...

Object # has no method 'validate' when posting in Express json,angularjs,express,mongoose,mean-stack
I'm trying to create a simple poll app with Angular and Express. I've gotten most of it done but the app crashes when POSTing data. The only error the express console seems to be spitting out is: node_modules\mongoose\lib\schema\documentarray.js:94 doc.validate(function (err) { ^ TypeError: Object # has no method 'validate' A...

Adding MeteorJS to an existing AngularJS/MEAN stack app

angularjs,meteor,mean-stack
I'm new to MeteorJS and I think it's a better alternative to the MEAN stack I used in one of my projects. I like the angular-meteor package (https://github.com/Urigo/angular-meteor) but I think it's mainly for adding AngularJS support to a MeteorJS app and not the other way around. How would you...

Can't get MongoDB to start?

mongodb,mean-stack
Version 2.67 of MongoDB is installed. When I run MongoD in Terminal (mac os x 10.95), here is the message I get. (BTW, I have tried Sudo)![Error][1] Alis-MacBook-Air:~ alitaghikhani$ mongod mongod --help for help and startup options 2015-02-08T19:00:43.915-0500 [initandlisten] MongoDB starting : pid=40591 port=27017 dbpath=/data/db 64-bit host=Alis-MacBook-Air.local 2015-02-08T19:00:43.916-0500 [initandlisten] 2015-02-08T19:00:43.916-0500...

Error: Can't set headers after they are sent , happen only after refreshing a page

node.js,mongoose,mean-stack
Every time i refresh a html page at route 'localhost:8080/' or login a user I will get this Error: Can't set headers after they are sent. As far as I know this problem happens due to callbacks that are accidentally called twice. The app doesn't crash or anything, its just...

Stylesheets not applied to webpage MEAN stack

javascript,html,css,mean-stack,hogan.js
I am trying to make a website using the MEAN stack with hogan instead of jade, but my stylesheet isn't applying to my webpage. My directory looks like this (not showing the module files since they are the originals and I did not edit them): web_folder - bin - www...

how to determine logged in user in a mean stack application

node.js,express,mean-stack,meanjs
I'm writing an app based on mean.js boiler plate In my server code (express) I need to make some decisions which are based on knowing who the logged in user is I have passport local accounts implemented. How can I determine in the server code the identity of the current...

Grunt serve adds '#' in the url

javascript,node.js,gruntjs,mean-stack
I'm trying to build a simple web app (I'm newbie in Node.js, Yeoman, Grunt) and I'm following this great tutorial - "Build a M.E.A.N web app". The only thing that I don't understand is why when running grunt serve I got urls like localhost:9000/#/projects. What's the point of the '#'?...

node throws module.js:340 error

javascript,angularjs,node.js,mean-stack
I'm using the MEANstack for a project and hit up this error when trying to load the model from seed.js: module.js:340 throw err; ^ Error: Cannot find module '..api/callout/callout.model' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (C:\onemore\server\config\seed.js:12:15) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10)...

Mean Angular Express

angularjs,express,mean-stack
I am new to MEAN. I am trying to write a program which list existing products and create new products. first, I use a "NEW" link-button and I want it to show a form in the page that I am already at, when that button is clicked BUT when I...

Why does my node application sends tons of get requests?

node.js,optimization,minify,mean-stack
Whenever I refresh a page in my MEAN application, my terminal that's running the application outputs tons of get requests. Is this slowing down my app? Can I get rid of some of these? GET / 304 113.645 ms - - GET /assets/stylesheets/css/bootstrap.min.css 304 11.846 ms - - GET /assets/stylesheets/css/animate.css...

Upload multiple images angular - mean stack

javascript,angularjs,multipartform-data,mean-stack
I'm currently working with a mean stack, and I want to be able to choose multiple pictures in my angular project. Each picture should then be loaded into some sort of thumbnail(with a remove button for each picture :o)), and first when I press the "save" button the pictures should...

Using “Mongojs.ObjectID” in Server linked to Angular controller

javascript,angularjs,node.js,express,mean-stack
I'm using the MEAN stack to build a web app. I am trying to filter data coming from the server by ObjectId based on params in my controller. My params work for key-values, such as filtering by name, but filtering by ObjectID does not work. I am using MongoJS with...

How to enable CORS in MEAN STACK web app?

angularjs,node.js,mean-stack
I am working on a MEAN-STACK application.Using Mean-cli packgae of node. in which i am using darksky weather API, in package name Information. I have 4 other packages in custom folder of mean app. how did i enable the CORS so that all API request did not fail and return...

Angular nested repeat, save to database not working

angularjs,node.js,mongoose,mean-stack
I'm using a MEAN application, and now I want to read data from my database, allow users to edit it, and update the changes to the database. Everything is working fine, except for the nested repeat, which value's I'm able to get, but not save to the database. Code: <div...

Csurf invalid csrf token Express / nodejs

node.js,cookies,express,csrf,mean-stack
I have this odd behavior I get an error just the first time my page loads, basically is 'EBADCSRFTOKEN' I've been trying to figure it out why it happens only the first time the page loads, if I hit refresh and get a new token everything works fine. the same...

Mongoose embedded document update not persisting

node.js,mongodb,mongoose,mean-stack
I'm currently working with the MEAN stack and I'm trying to update an embedded document. Everything appears to work on execution, but the data does not persist after a refresh: // Soon to be update answer exports.updateAnswer = function(req, res) { var ansId = req.params.aid; var result; Poll.findById(req.params.id,function(err, poll){ if(err)...

Saving subdoc ref and parent document simultaneously

mongodb,mongoose,mean-stack
I have a users model with a ref to company. My data is as follows: { "name":"justin", "notes":"hello notes", "company": {"name":"acme inc"} } Is it possible to save my data as a single call or would I need to save my company model first, then save my user afterward? var...

Express selecting multiple model data

javascript,express,routing,mean-stack
I'm learning the MEAN stack and want to select multiple models when routing with express. I need to select one model then based on it's values a few others. Here's the main model: var mongoose = require('mongoose'); var MatchSchema = new mongoose.Schema({ title: String, type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Game'...

MongoDB is posting no data with Mongoose

angularjs,node.js,mongodb,mongoose,mean-stack
I am making an app with the MEAN stack and I am having trouble POSTing data to my database. When I push the submit button, the form data is being cleared, like it is supposed to when the POST is sucessful, but when I go to the database, there is...

how to Host Angularjs app or M.E.A.N. client side app on a Apache or a NodeJS server?

angularjs,node.js,apache,host,mean-stack
I just developed a basic CRUD functioning MEAN stack app. I hosted the server side api i.e. build in nodejs. But, I'm finding difficulty in hosting the client side UI. It is build with angularjs has bower components and grunt serve. Both are running perfect in my client side. Can...

Is it a good idea to develop two separate node application for serving webservice and for consuming webservice to render it on browser? [closed]

javascript,node.js,web-services,mean-stack
If we are running two different node instance one of each purpose( webservice engine/data engine and webservice consumer) will it be good or keeping both the purpose in same application will be better ?

content is loading everytime I refresh the page

javascript,angularjs,node.js,mean-stack
I'm developing a simple CRUD application with MEAN stack. So the scenario is a user post a data to the server and it will render the data in real-time. Everything works fine but whenever I refresh the page , It will sort of loads all the content, every time it...

How to make changes once MEANJS app is deployed?

git,gruntjs,mean-stack,meanjs
So this may be a basic question, but I am unable to figure this one out. Also this is my first MEAN app, so excuse the ignorance. I have successfully deployed my MEANJS app onto the remote server in a test folder. Everything is working fine. I then cloned the...

MEAN stack: angular routing vs express routing [closed]

angularjs,express,routing,mean-stack,angular-routing
I've started using angular in my express generated projects and i'm loving it. Recently I implemented angular routing into one of my test projects and I'm wondering what the advantages and disadvantages are to using angular routing over pure express/node routing (e.g. are there technical issues with this way, or...

Angularjs storing $scope variable

angularjs,node.js,angularjs-directive,angularjs-scope,mean-stack
I'm building a web app using Yeoman Angular-fullstack. I'm confused about how to update my $scope variables so that once a change is made, the results are automatically displayed on the html page without a refresh. HTML <h1 class="page-header">Drugs:</h1> <div class="row"> <div class="col-sm-4 col-sm-offset-4"> <div ng-repeat="current in alldrugs"> <p> <a...

Create link to Wordpress blog from MEANJS app in the same domain nginx

node.js,wordpress,apache,nginx,mean-stack
I am running a Node app at port 3000, which my Nginx server is successfully redirecting to from port 80. But within my Node app I have a wordpress blog which I am running using Apache at port 8080. I am unable to link node app to this blog, and...

How do you get the created object of a findOneAndUpdate with {upsert: true} in MongooseJS? [duplicate]

node.js,mongodb,mongoose,mean-stack,meanjs
This question already has an answer here: Mongoose findByIdAndUpdate upsert returns null document on initial insert 1 answer What I am doing: Book.findOneAndUpdate( {_id: id_from_api}, {$set: bookObj}, {upsert: true}, function (err, book) { handleError(err); console.log(book); } ); I am expecting book to be a book document but it is...

Angular authentication using Passport for Ionic App

angularjs,node.js,ionic-framework,ionic,mean-stack
I've built an API for my web app, which is built using MEAN stack. Now I am trying to use this API on mobile client side which is built using Ionic Framework. I'm using this code to perform an $http call to API: $http.post(ServerIP+'/login', {username: $scope.credentials.username, password: $scope.credentials.password}).success(function(response) { $scope.authentication.user...

npm install -g generator-X error in windows

angularjs,node.js,npm,mean-stack,yeoman-generator
Both producing same error. npm install -g generator-angular-fullstack. npm install -g generator-meanjs. I tried everthing (googling and stackoverflow) but this problem is scratching my head from the last 3-4 hours Any support would be helpfull I tried npm install -g generator-angular-fullstack or npm install -g generator-meanjs Initially it said python...

Add users roles in Meanjs

roles,mean,mean-stack,meanjs
Recently I began to use MeanJs, it's pretty amazing but I don't understand some stuff. I need to create a simple user management for my backend. From official blog they say: New usability features: Added roles to the User model - the defaults are ‘user’ and ‘admin’, you can add...

Mean stack two index pages and 2 deiffrent ui views?

angularjs,routing,mean-stack
I want to do the following: i have a single program with 2 diffrent "layouts", one in localhost:3000 and one in localhost:3000/admin In both i have diffrent css files rendered, both have diffrent template structure, but both! share the same js. I want one ui-view to go to "home" page...

Mean io cant install module meanio

javascript,node.js,mean-stack
I am trying to install mean io app and i get this error when its come to meanio module. npm WARN locking Error: EACCES, open '/Users/netanelbasal/.npm/_locks/cookie-parser-a838fb939a0365d3.lock' npm WARN locking /Users/netanelbasal/.npm/_locks/cookie-parser-a838fb939a0365d3.lock failed { [Error: EACCES, open '/Users/netanelbasal/.npm/_locks/cookie-parser-a838fb939a0365d3.lock'] ...

Mongoose relation not working both ways

express,mongoose,mean-stack
I can't get a relationship running between my Rides and Comments controller in my app (built using the yeoman angular-fullstack generator). Comment model: var mongoose = require('mongoose'), Schema = mongoose.Schema; var CommentSchema = new Schema({ name: String, comment: String, active: Boolean, ride: { type: mongoose.Schema.Types.ObjectId, ref: 'Ride' } }); module.exports...

File upload with nodejs, express, mean stack

javascript,angularjs,node.js,express,mean-stack
I am new to Mean and nodejs. I have a old project with old dependencies. And I am trying to upload image file to server using angular js. But it does not work. I don't know how to retrieve image file data, name, type, etc at both client and server...