标签: mean-stack

如何在Nitrous.IO上设置MEAN(Mongo,Express,Angular和Node)堆栈

我利用即将到来的周末来检查2013年项目清单中的两件事:

  • 尝试云开发
  • 试试ANGULAR.JS

我的游戏计划是在Nitrous.IO上设置MEAN堆栈,然后使用堆栈完成在线提供的众多Angularjs教程项目之一.

问题:

  1. 我有兴趣听听是否有人在Nitrous或其他方面设置了MEAN堆栈,或者是否有人知道有任何好的博客文章通过这个过程为那些几乎没有javascript开发经验的人.

  2. 此外,如果您已经设置了MEAN堆栈,那么您可以采用不同的方式做任何事情,或者我应该注意哪些宝贵的资源.

我觉得有些资源很有用:

过去一周我一直在网上进行研究并发现了一些很好的资源,但看到其他人发现或建议的内容会很棒.以下是我遇到的一些可能对其他人有帮助的资源的链接:

  1. 构建Angular Start-up Stack - 多伦多Meetup Stream
  2. Egghead.io提供一些关于Angular的精彩视频教程
  3. Google的Angular网站拥有丰富的信息.
  4. 亚马逊AWS上的MEAN上的 USC Linux用户组Youtube视频

提前感谢任何资源,见解或指导.

mongodb node.js angularjs nitrousio mean-stack

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

使用javascript fullstack进行Passport google身份验证

我正在尝试在我的应用程序中添加带有护照的google身份验证,这是使用yeoman fullstack-generator生成的.

在我的登录控制器内我有这个请求:

$scope.googleAuth = function(){
  $http.get('/auth/google');
};
Run Code Online (Sandbox Code Playgroud)

但是,当我调用此函数时,我有这个错误:

XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=h…d=<my-client-ID-here>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

我试图修复在express.js文件中添加中间件层的问题:

app.use(function (req, res, next) {

  // Website you wish to allow to connect
  res.setHeader('Access-Control-Allow-Origin', 'http://localhost:9000');

  // Request methods you wish to allow
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

  // Request headers you wish to allow
  res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

  // Set to true if you need the website to include cookies …
Run Code Online (Sandbox Code Playgroud)

express angularjs mean-stack passport.js

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

AngularJS代码不能与NodeJS一起使用

我是MEAN Stack的新手.我在html中尝试了一些非常基本的东西,当我在浏览器中打开它时,会使用一些angularJS.但遗憾的是,当我尝试使用nodeJS服务器渲染代码时,代码不再起作用了.显示index.html但角度部分不再起作用.我的输出只是{{article}}.你有什么建议吗 ?

的index.html

<html ng-app="ibrahimsBlog">

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Ibrahims Blog</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body>

  <div ng-controller="articleController">
    <div ng-repeat="article in articles">
      {{article}}
    </div>
  </div>  

  </body>

</html>
Run Code Online (Sandbox Code Playgroud)

app.js

var app = angular.module('ibrahimsBlog', [])
app.controller('articleController', [
'$scope',
function($scope) {
  $scope.articles = [
    'foo',
    'bar',
    'baz'
  ];
}]);
Run Code Online (Sandbox Code Playgroud)

而我非常基本的节点服务器:

var express = require('express'), app = express();

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/index.html');
});

app.listen(3000, function() {
  console.log('Server listening on port 3000');
});
Run Code Online (Sandbox Code Playgroud)

node.js angularjs mean-stack

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

MEAN.io和Sails.js之间的区别

这两者有什么区别?它们是互斥的,还是可以同时运行sails.js和mean.io?如果它们是相互排斥的,那么使用一个而不是另一个的利弊?

node.js express sails.js mean-stack mean.io

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

Router.use需要中间件功能吗?

所以我试图在一个名为login_routes.js的独立JS文件中分离我的登录路由

我一直收到这个特定的错误:

TypeError:Router.use()需要中间件函数,但在Function处有一个Object.(/Users/ethanthomas/Desktop/mean-stuff/express-server/node_modules/express/lib/router/index.js:446:13)

不完全理解它要求我做implement什么?

login_routes.js:

var express = require('express');
var app = express();

app.route('/login')

.get(function(req, res, next) {
    res.send('this is the login form');
})

.post(function(req, res, next) {
    console.log('processing');
    res.send('proccessing the login form!');
});
Run Code Online (Sandbox Code Playgroud)

server.js:

var express = require('express');
var app = express();
var path = require('path');
var adminRoutes = require('./app/routes/admin_routes');
var loginRoutes = require('./app/routes/login_routes');

app.use('/admin', adminRoutes);
app.use('/login', loginRoutes);


//send our index.html file to the user for the home page
app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname + '/index.html'));
}); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express mean-stack

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

如何让Mongoose列出集合中的所有文档?要判断集合是否为空?

我正在使用MEAN堆栈并在Mongoose中编写这些方法.我想知道我放在Mongoose模型文件中的内容有什么问题.我想使用Mongoose简单地打印出myModel集合中所有文档的列表.

myModel.methods.myMethod = function(cb){
  this.model("Bids").find({}, 'myField', function(err, results){
    if (err){console.log(err);return err;}
    console.log("okay");
    console.log(results);
  })
  this.save(cb);
}
Run Code Online (Sandbox Code Playgroud)

另外,我可以在Mongoose中编写什么代码来判断myModel集合是否为空?


教一个男人如何钓鱼比给他一条鱼更好......

因此,如果您可以建议我可以安装哪些调试工具(例如Express中间件),这将有助于我自我调试,这将非常有用.请在此处发布您的调试建议.

javascript mongoose mongodb node.js mean-stack

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

何时在Angularjs中使用$ q.defer()

我是Angularjs的新手,我正在学习本教程:http://mherman.org/blog/2015/07/02/handling-user-authentication-with-the-mean-stack/#.WE70iubhCM8 .但是我不明白何时使用$ q.defer().例如,在下面的Angularjs代码中,为什么要使用$ q.defer():

function login(username, password) {

      // create a new instance of deferred
      var deferred = $q.defer();

      // send a post request to the server
      $http.post('/user/login',
        {username: username, password: password})
        // handle success
        .success(function (data, status) {
          if(status === 200 && data.status){
            user = true;
            deferred.resolve();
          } else {
            user = false;
            deferred.reject();
          }
        })
        // handle error
        .error(function (data) {
          user = false;
          deferred.reject();
        });
Run Code Online (Sandbox Code Playgroud)

服务器端代码是:

router.post('/login', function(req, res, next) {
  passport.authenticate('local', function(err, user, info) …
Run Code Online (Sandbox Code Playgroud)

javascript promise angularjs mean-stack

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

配置角度cli构建监视模式和nodemon监视的最佳方法是什么?

嗨,我正在开发一个使用角度4的平均应用程序.我使用了角度cli配置.我想使用监视模式自动构建代码,并且还希望在任何文件更改时重新启动节点服务器.

我使用了以下命令但没有工作

script: {
   "server": "ng build -w && nodemon --watch src/**/*.ts --exec ts-node ./bin/www"
}
Run Code Online (Sandbox Code Playgroud)

我已将配置保存在从其他位置bin/www导入的目录文件中server.ts.

上面命令的问题是,ng cli正在构建启用了watch的代码,但nodemon没有启动.

所以我尝试了以下内容.但它的建筑只有一次作为手表没有启用cli.

script: {
   "server": "ng build && nodemon --watch src/**/*.ts --exec ts-node ./bin/www"
}
Run Code Online (Sandbox Code Playgroud)

在任何一种情况下,nodemon都无法工作.

express nodemon mean-stack angular-cli angular

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

Angular 6错误TS1135:应使用参数表达式

我正在跟踪有关如何通过此链接构建MEAN堆栈的教程:https : //www.youtube.com/watch?v= wtIvu085uU0,但是我仍然坚持在59:34左右创建角度部分。本教程使用angular2,而我使用angular6。阻止我前进的主要部分是contact.service.ts,并使addContacts,getContacts和deleteContact方法能够正常工作,因为.map方法自从angular 2开始就发生了变化。

getContacts() {
    return this.http.get('http://localhost:3000/api/contacts')
        .map(res => res.json());
}
Run Code Online (Sandbox Code Playgroud)

返回“属性'地图'在'可观察'类型上不存在”的错误

getContacts() {
    return this.http.get('http://localhost:3000/api/contacts')
        .pipe(
            .map(res => res.json())
        );
}
Run Code Online (Sandbox Code Playgroud)

现在返回“ src / app / contact.service.ts(17,7)中的错误:错误TS1135:期望参数表达式。” 在控制台中,我认为我已经克服了地图错误,但是我不知道Argument表达式预期的错误是什么意思。在将地图更改为管道之前和之后,其他两种方法都存在相同的问题。现在,它不会编译并显示视频中显示的“联系人工作”页面,该页面位于1:03:37。控制台在其他类中没有显示其他错误,因此我认为这是唯一的错误。

mean-stack angular

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

当我尝试运行此代码时,出现以下错误

我正在尝试通过此代码连接mongodb数据库,但是在运行此代码时,我得到了错误(代码底部的错误)。错误之一在第七行,通过添加解决了该错误, { useNewUrlParser: true }但仍有更多错误。我正在使用MongoDB版本4.0.1。是否有人知道如何解决此错误。

const express = require('express');     
const mongoose = require('mongoose');  
const bodyParser = require('body-parser');   
const app = express();

app.use(express.static('public'));  
app.set('view engine','ejs');

mongoose.connect('mongod://localhost/students', { useNewUrlParser: true });  
var studentSchema = new mongoose.Schema({  
    name: String,  
    age:Number,  
    country:String  
});

var Student = mongoose.model("Student", studentSchema);  
var shashank = new Student({  
    name:"Shashank",  
    age:"21",  
    country:"India"  
});    

shashank.save((err,student) => {    
    if(err){     
        console.log('Something went wrong!');     
    }    
    else {      
        console.log("You added: " + student);      
    }      
});      

app.listen(3000,() => {     
    console.log('Server Listening!');     
});
Run Code Online (Sandbox Code Playgroud)

运行此代码时出错! …

mean mongodb node.js express mean-stack

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