我正在使用res.send,无论如何,它返回200的状态.我想为不同的响应设置该状态为不同的数字(错误等)
这是用的 express
我的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?
这是我的档案: 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) 我的看法:
<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()">×</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) 在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) 我有
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) 我正在使用node.js进行一些文件操作工作,我使用的许多软件包都需要发送"路径",以便他们可以打开文件,做一些工作,等等.
但我正在解析数百万个文件,而不是实际将它们存储在磁盘上,我想将它们存储在内存中.这些文件的内容都在我的数据库中,我讨厌将它们写入磁盘,只是为了对它们进行疯狂的工作.
这样的事情可能吗?
我的.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) 我正在使用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)
我得到数据.所以我对这里发生的事情感到有些困惑.
javascript ×5
node.js ×3
express ×2
angularjs ×1
associations ×1
coffeescript ×1
epilogue ×1
eslint ×1
file-io ×1
html ×1
jshint ×1
lint ×1
mongo-shell ×1
mongodb ×1
ng-submit ×1
resize ×1
sequelize.js ×1
typescript ×1