小编Sha*_*oon的帖子

如何使用Node.js/Express发回响应头?

我正在使用res.send,无论如何,它返回200的状态.我想为不同的响应设置该状态为不同的数字(错误等)

这是用的 express

node.js response-headers express

25
推荐指数
5
解决办法
7万
查看次数

如何使用CoffeeScript设置setInterval?

我的JavaScript如下:

var util = require('util');
EventEmitter = require('events').EventEmitter;

var Ticker = function() {
      var self = this;
      setInterval( function() {
        self.emit('tick');
      }, 1000 );
    }
Run Code Online (Sandbox Code Playgroud)

什么是等效的CoffeeScript?

javascript coffeescript

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

jshint"使用严格"的问题

这是我的档案: app/scripts/controllers/main.js

"use strict";

angular.module('appApp')
  .controller('MainCtrl', ['$scope', function ($scope) {
    $scope.awesomeThings = [
      'HTML5 Boilerplate',
      'AngularJS',
      'Karma'
    ];
  }]);
Run Code Online (Sandbox Code Playgroud)

Gruntfile.coffee有:

jshint:
    options:
        globals:
            require: false
            module: false
            console: false
            __dirname: false
            process: false
            exports: false

    server:
        options:
            node: true
        src: ["server/**/*.js"]

    app:
        options:
            globals:
                angular: true
                strict: true

        src: ["app/scripts/**/*.js"]
Run Code Online (Sandbox Code Playgroud)

当我跑步时grunt,我得到:

Linting app/scripts/controllers/main.js ...ERROR
[L1:C1] W097: Use the function form of "use strict".
"use strict";
Run Code Online (Sandbox Code Playgroud)

jshint

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

ng-submit不在angularjs中工作

我的看法:

<div class="modal" tabindex="-1" role="dialog" ng-controller="LocationController">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" ng-click="$hide()">&times;</button>
        <h4 class="modal-title">
          Add a Location
        </h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal" role="form" ng-submit="createLocation()">
          <div class="form-group">
            <label class="col-sm-2 control-label">Name</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" placeholder="Warehouse A, Row 15, Shelf BC1, etc" ng-model="name">
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">Type</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" placeholder="warehouse, row, shelf, etc" ng-model="type">
            </div>
          </div>

        </form>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Save</button>
        <button type="button" class="btn btn-danger" ng-click="$hide()">Cancel</button>
      </div> …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs ng-submit

24
推荐指数
3
解决办法
5万
查看次数

我可以在缩放时停止调整元素的大小吗?

我有一个标准的网站,当用户放大(CTRL +)时,如何防止元素调整大小?

html resize

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

更新MongoDB shell中的查询

在shell中,我的查询是:

db.checkin_4e95ae0926abe9ad28000001.update({location_city:"New York"}, {location_country: "FUDGE!"});
Run Code Online (Sandbox Code Playgroud)

但是,它实际上并没有更新我的记录.它也没有错误.当我执行db.checkin_4e95ae0926abe9ad28000001.find({location_city:"New York"});此操作后,我得到了所有结果,但location_country没有改变:

{
    "_id": ObjectId("4e970209a0290b70660009e9"),
    "addedOn": ISODate("2011-10-13T15:21:45.772Z"),
    "location_address1": "",
    "location_city": "New York",
    "location_country": "United States",
    "location_latLong": {
        "xLon": -74.007124,
        "yLat": 40.71455
    },
    "location_source": "socialprofile",
    "location_state": "New York",
    "location_zip": ""
}
Run Code Online (Sandbox Code Playgroud)

mongodb mongo-shell

21
推荐指数
3
解决办法
5万
查看次数

使用结语,是否可以在没有关联的情况下获取资源?

我有

epilogue.resource({
  model: db.Question,
  endpoints: ['/api/questions', '/api/questions/:id'],
  associations: true
});
Run Code Online (Sandbox Code Playgroud)

所以,当我点击时/api/questions,我会恢复与资源的所有关联.在某些情况下,我是否可以通过某些内容来获取关联?或者我应该创建一个新的端点:

epilogue.resource({
  model: db.Question,
  endpoints: ['/api/questions2', '/api/questions2/:id']
});
Run Code Online (Sandbox Code Playgroud)

javascript associations sequelize.js epilogue

21
推荐指数
1
解决办法
1342
查看次数

我可以使用Node.js将文件存储在"内存"中吗?

我正在使用node.js进行一些文件操作工作,我使用的许多软件包都需要发送"路径",以便他们可以打开文件,做一些工作,等等.

但我正在解析数百万个文件,而不是实际将它们存储在磁盘上,我想将它们存储在内存中.这些文件的内容都在我的数据库中,我讨厌将它们写入磁盘,只是为了对它们进行疯狂的工作.

这样的事情可能吗?

javascript file-io node.js

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

eslint / typescript:无法解析模块的路径

我的.eslintrc.json是:

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true,
        "node": true,
        "jest": true
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "prettier",
        "import"
    ],
    "extends": [
        "airbnb",
        "airbnb/hooks",
        "plugin:@typescript-eslint/recommended",
        "plugin:react/recommended",
        "plugin:import/errors",
        "plugin:import/warnings",
        "plugin:import/typescript",
        "prettier"
    ],
    "root": true,
    "rules": {
        "no-const-assign": 1,
        "no-extra-semi": 0,
        "semi": 0,
        "no-fallthrough": 0,
        "no-empty": 0,
        "no-mixed-spaces-and-tabs": 0,
        "no-redeclare": 0,
        "no-this-before-super": 1,
        "no-unreachable": 1,
        "no-use-before-define": 0,
        "constructor-super": 1,
        "curly": 0,
        "eqeqeq": 0,
        "func-names": 0,
        "valid-typeof": 1,
        "import/extensions": 0, …
Run Code Online (Sandbox Code Playgroud)

javascript lint typescript eslint

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

为什么req.params返回一个空数组?

我正在使用Node.js,我想看到已经发布到我的脚本的所有参数.为了实现我的功能,在我的routes/index.js工作中:

app.post('/v1/order', order.create);
Run Code Online (Sandbox Code Playgroud)

然后在我的功能中,我有:

exports.create = function(req, res, next) {
 console.log( req.params );
Run Code Online (Sandbox Code Playgroud)

但它返回一个空数组.但当我这样做时:

exports.create = function(req, res, next) {
 console.log( req.param('account_id') );
Run Code Online (Sandbox Code Playgroud)

我得到数据.所以我对这里发生的事情感到有些困惑.

node.js express

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