标签: mean-stack

"你的npm版本已经过时了." 但事实并非如此.安装哟

在Windows 7 64位上.通过向导安装Node.js给了我npm.

我运行npm install -g yo并获得以下内容

你的npm版本已经过时了.

完成输出:

C:\Users\dlite922>npm install -g yo
|


> spawn-sync@1.0.11 postinstall C:\Users\dlite922\AppData\Roaming\npm\node_modules\yo\node_modules\cross-spawn\node_modules\spaw
> node postinstall

C:\Users\dlite922\AppData\Roaming\npm\yo -> C:\Users\dlite922\AppData\Roaming\npm\node_modules\yo\lib\cli.js

> yo@1.4.7 postinstall C:\Users\dlite922\AppData\Roaming\npm\node_modules\yo
> yodoctor


Yeoman Doctor
Running sanity checks on your system

? Global configuration file is valid
? NODE_PATH matches the npm root
? Node.js version
× npm version

Your npm version is outdated.

Upgrade to the latest version by running:
npm install -g npm

See this guide if you're having trouble upgrading: …
Run Code Online (Sandbox Code Playgroud)

node.js npm yeoman mean-stack

15
推荐指数
1
解决办法
5323
查看次数

是否有可能通过angularJs将param从州传递到州?

我希望从一个商店状态传递一个参数到产品状态的显示产品信息:

我的应用程序 - storeApp

.config(['$stateProvider', function($stateProvider) {
$stateProvider
    .state('store', {
        url: '/store',
        templateUrl: 'store/store',
        controller: 'storeCtrl'
    })
    .state('products', {
        url: '/products/:productSku',
        templateUrl: 'store/product',
        controller: 'productCtrl',
        resolve: {
                productResource: 'productFactory',
                _product: function(productResource, $stateParams){
                return productResource.getProduct($stateParams.productSku);
                    }
                }
Run Code Online (Sandbox Code Playgroud)

Store.jade

a(href='/products/{{product.sku}}')
Run Code Online (Sandbox Code Playgroud)

产品控制器

.controller("productCtrl", function ($rootScope, $http, $stateParams, productFactory, storeFactory) {
//.controller('productCtrl', ['_product', function ($scope, $rootScope, storeFactory, _product) {

console.log($stateParams.productSku);
Run Code Online (Sandbox Code Playgroud)

产品工厂

function getProduct(sku) {
    return $http.get('http://localhost:3000/api/products/' + sku );
}
Run Code Online (Sandbox Code Playgroud)

由于我使用的是MEAN Stack,所以节点附有路由器来表示:

Server.js

const storeController = require('./controllers/store');
server.get('/store/product', passportConfig.isAuthenticated, storeController.getProductPage);
Run Code Online (Sandbox Code Playgroud)

Store.js

exports.getProductPage = (req, …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angular-ui-router mean-stack pug

15
推荐指数
1
解决办法
433
查看次数

GET错误MEAN App

我一直在学习如何使用MEAN堆栈来构建Web应用程序,到目前为止它已经很有趣了.我没有使用yeoman生成器或npm应用程序为我生成代码,而是从头开始构建我的整个应用程序.通过这种方式,我知道每个部分如何连接以及我的应用程序发生了什么.当我查看开发人员控制台并看到时,我刚开始连接应用程序的前端和后端

GET http://blog.dev/bower_components/angular/angular.js
Run Code Online (Sandbox Code Playgroud)

不仅有角度,还有我拥有的其他资源(Modernizr,angular-routes,mootools,restangular等等).使用yeoman角度生成器时,您可以运行grunt serve命令启动角度侧.因为我从头开始构建应用程序,我使用npm作为构建工具,我不知道如何构建前端服务器.所以,我只是使用一个指向我的index.html的简单nginx虚拟主机.这是配置:

server {
        listen 80;

        server_name blog.dev;

        root /home/michael/Workspace/blog/app;
        index index.html index.htm;

        location / {
                try_files $uri $uri/ =404;
        }
}
Run Code Online (Sandbox Code Playgroud)

我不确定其他变量可能会对这种情况产生什么影响,所以如果我错过了什么,请告诉我,我很乐意为您提供所需的信息!

nginx node.js angularjs mean-stack

14
推荐指数
1
解决办法
265
查看次数

用于MEAN堆栈的IDE [MongoDb,Express,AngularJs,NodeJs]

为了设计MEAN堆栈应用程序,我正在创建单独的模块(angularjs,expressjs,nodejs,mongodb),我手动链接它们.您能否建议我使用IDE直接设计MEAN堆栈应用程序.

mean-stack

13
推荐指数
1
解决办法
2万
查看次数

将子文档添加到现有mongodb文档

本质上,我只是尝试将新的子文档添加到具有以下模式的现有mongodb文档中

/models/server/destination.js

// this is the "destination" model for mongoose
var mongoose = require('mongoose')
var Adventure = require('../models/adventure')

// this is the schema that every entry will get when a new trip is made.
var tripSchema = mongoose.Schema({
    name: { type: String, required: true },
    city: { type: String, required: true },
    dateStart: { type: Date, required: true },
    dateFinish: { type: Date, required: true },
    adventures: [Adventure]
})

// module.exports makes this model available to other file 
module.exports = …
Run Code Online (Sandbox Code Playgroud)

addchild mongoose mongodb mean-stack mongoose-schema

13
推荐指数
1
解决办法
3393
查看次数

Mongoose如何保存回调功能?

对于MEAN堆栈,我正在学习Mongoose的save()函数,它接受回调.其API说明:

Model#save([options], [fn])

Saves this document.

Parameters:

[options] <Object> options set `options.safe` to override [schema's safe option](http://mongoosejs.com//docs/guide.html#safe)
[fn] <Function> optional callback
Run Code Online (Sandbox Code Playgroud)

我如何知道可选回调中的参数?API仅举例说明:

product.sold = Date.now();
product.save(function (err, product, numAffected) {
  if (err) ..
})
The callback will receive three parameters

err if an error occurred
product which is the saved product
numAffected will be 1 when the document was successfully persisted to MongoDB, otherwise 0.
Run Code Online (Sandbox Code Playgroud)

我认为API应该说的可选回调如下:

[fn] <Function> optional callback with this structure:

     function(err, theDocumentToBeSaved, [isSaveSuccessful])
Run Code Online (Sandbox Code Playgroud)

它可以像下面这样使用.请注意,第二个参数(文档)必须与调用save的文档相同. …

javascript mongoose mongodb node.js mean-stack

13
推荐指数
1
解决办法
3万
查看次数

MEAN堆栈文件上传

我正在开发一个MEAN堆栈Web应用程序,我想使用ng2-file-upload上传文件.这是我的Angular 2代码.

classroom.component.html

    <input type="file" class="form-control" name="single" ng2FileSelect [uploader]="uploader" />
    <button type="button" class="btn btn-success btn-s"
                  (click)="uploader.uploadAll()" [disabled]="!uploader.getNotUploadedItems().length">
            <span class="glyphicon glyphicon-upload"></span> Upload all
          </button><br />
Run Code Online (Sandbox Code Playgroud)

classroom.component.ts

uploader:FileUploader = new FileUploader({url: "http://localhost:3000/api/material/create-material"});
Run Code Online (Sandbox Code Playgroud)

在server.js中

app.use(cors());
app.use('/api',api);
app.use('/api/material',material);
Run Code Online (Sandbox Code Playgroud)

并在material.js

var storage = multer.diskStorage({ //multers disk storage settings
    destination: function (req, file, cb) {
        cb(null, './uploads/');
    },
    filename: function (req, file, cb) {
        var datetimestamp = Date.now();
        cb(null, file.fieldname + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1]);
    }
});

var upload = multer({ //multer …
Run Code Online (Sandbox Code Playgroud)

javascript node.js mean-stack angular

13
推荐指数
2
解决办法
859
查看次数

MEANJS:413(请求实体太大)

我正在使用MEANJS堆栈,我使用ng-flow上传图像并将imgsrc保存为base64 url​​.

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARkAAACzCAYAAAC94GgrA....

这是我的猫鼬模式:

var ServiceSchema = new  mongoose.Schema({
    name : String,
    url: String,
    description : String,
    category : String,
    imgsrc: String
});
Run Code Online (Sandbox Code Playgroud)

我遇到大图像的请求实体太大服务器错误.

我可以在上传之前调整图像大小,但这仍然只允许我200 x 200的图像

$scope.resizeimageforupload = function(img){
        var canvas = document.getElementById('canvas');

        var MAX_WIDTH = 200; //400; too big still
        var MAX_HEIGHT = 200; //300 too big still
        var width = img.width;
        var height = img.height;

        if (width > height) {
          if (width > MAX_WIDTH) {
            height *= MAX_WIDTH / width;
            width = MAX_WIDTH; …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb angularjs mean-stack

12
推荐指数
1
解决办法
1万
查看次数

Javascript删除对象属性不起作用

我正在MEAN.js上运行一些项目,我遇到了以下问题.我想做一些用户的配置文件计算并将其保存到数据库.但是用户模型中的方法存在问题:

UserSchema.pre('save', function(next) {
    if (this.password && this.password.length > 6) {
        this.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64');
        this.password = this.hashPassword(this.password);
    }
    next();
});
Run Code Online (Sandbox Code Playgroud)

如果我将使用我的更改发送密码,它将更改凭据,因此用户下次无法登录.我想在保存之前从用户对象中删除密码,但是我无法做到(让我们看看下面代码中的注释):

exports.signin = function(req, res, next) {
    passport.authenticate('local', function(err, user, info) {
        if (err || !user) {
            res.status(400).send(info);
        } else {
            /* Some calculations and user's object changes */
            req.login(user, function(err) {
                if(err) {
                    res.status(400).send(err);
                } else {
                    console.log(delete user.password); // returns true
                    console.log(user.password); // still returns password :(
                    //user.save();
                    //res.json(user);
                }
            });
        }
    })(req, res, next);
}; …
Run Code Online (Sandbox Code Playgroud)

javascript mean-stack

12
推荐指数
4
解决办法
2万
查看次数

Mongoose:错误无法找到模块调试

我正在构建一个基本的MEAN webapp并且是新的堆栈.我的前端正在运行,但只要我将以下行添加到app.js:

var mongoose = require('mongoose');
require('./models/test');
mongoose.connect('mongodb://localhost:3000/design-data-test');
Run Code Online (Sandbox Code Playgroud)

我在终端中收到以下错误:

Error: Cannot find module 'debug'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/username/node_modules/mongoose/node_modules/mquery/lib/mquery.js:11:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
Run Code Online (Sandbox Code Playgroud)

并且我的所有前端代码都停止运行.Mongodb正在默认端口上运行.

我该如何解决这个错误?

mongoose mongodb node.js express mean-stack

11
推荐指数
2
解决办法
1万
查看次数