我刚刚使用typescript开始了一个新的nodejs项目.我安装了Typings(https://github.com/typings/typings)并用它来安装节点v4.x和express v4.x的参考文件.
我的节点版本是v4.2.6我的打字稿版本是v1.7.5
我的项目目录如下:
package.json
tsconfig.json
typings.json
src/
app.ts
typings/
main.d.ts
main/ambient/node/node.d.ts
main/ambient/express/express.d.ts
Run Code Online (Sandbox Code Playgroud)
typings/main.d.ts的内容如下:
/// <reference path="main/ambient/express/express.d.ts" />
/// <reference path="main/ambient/node/node.d.ts" />
Run Code Online (Sandbox Code Playgroud)
tsconfig.json的内容如下:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
}
}
Run Code Online (Sandbox Code Playgroud)
typings.json的内容如下:
{
"dependencies": {},
"devDependencies": {},
"ambientDependencies": {
"express": "github:DefinitelyTyped/DefinitelyTyped/express/express.d.ts#dd4626a4e23ce8d6d175e0fe8244a99771c8c3f2",
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#1c56e368e17bb28ca57577250624ca5bd561aa81"
}
}
Run Code Online (Sandbox Code Playgroud)
src/app.ts的内容如下:
'use strict';
///<reference path="../typings/main.d.ts"/>
import * as express from "express";
Run Code Online (Sandbox Code Playgroud)
这非常简单,应该会产生一个基本的应用程序.但是,当我尝试编译它时,我得到了错误error TS2307: Cannot find module 'express'.
我已经尝试重新排列打包文件,更改引用路径标记中的相对路径,使用files
tsconfig.json中的字段来指示引用路径而不是在文件中使用内联标记,但都无济于事.我也曾尝试使用编制gulp-typescript
,gulp-tsc
以及tsc
直接在命令行.
我得到类似的错误,当我尝试使用建立的NodeJS式模块,例如crypto
,http
, …
我们有一个nodejs + mongodb应用程序,它已经在生产中运行了好几年,并且在多台机器上进行开发.在一个开发人员的机器上,我看到了错误
MongoError: collection already exists
Run Code Online (Sandbox Code Playgroud)
研究此错误表示仅在集合处于严格模式时尝试创建现有集合时才会发生此错误.我们不会在应用程序的任何地方调用mongo的严格模式,我们只能在一台机器上重现此错误.
导致此错误的代码如下:
var mongo = require('mongodb');
mongo.MongoClient.connect(config.mongoConnectionString, {w:1}, function(err, db) {
db.createCollection('accounts', function(err, collection) {
// "err" here is the error message.
});
});
Run Code Online (Sandbox Code Playgroud)
有没有办法覆盖mongo的默认strict: false
值?是否有全局配置选项导致严格模式打开?我宁愿不修改代码来strict: false
为每个集合指定只是为了启用单个开发人员.开发人员正在运行mongo v3.2
我的套接字将连接,但无法接收任一方向的消息。我设置了如下所示的日志记录。在服务器端,我看到正在记录连接,并在页面关闭时记录断开连接。如果我终止服务器,客户端会记录“套接字已断开”。但没有收到任何方向的排放。我做了更多日志记录并确定客户端套接字的socket.connected
字段是false
.
此时我完全不知所措。从字面上看,一旦我建立连接,客户端就会认为其套接字已断开连接,但当我关闭浏览器窗口时,服务器仍然看到它已断开连接。我正在运行 socket.io 1.1.0。谢谢你的帮助!
服务器:
io.sockets.on('connection', function(socket) {
logger.info('Socket connected. ID: ' + socket.id);
socket.on('refresh', function() {
logger.info('Refresh received from ID: ' + socket.id);
});
socket.on('disconnect', function() {
logger.info('Disconnect received from ID: ' socket.id);
});
});
Run Code Online (Sandbox Code Playgroud)
客户:
var socket;
$(document).ready(function() {
socket = io.connect('http://localhost');
console.log(socket.connected);
socket.emit('refresh');
socket.on('disconnect', function() {
console.log("Socket disconnected.");
});
});
Run Code Online (Sandbox Code Playgroud) 我有一个 Jenkins 管道,它在 Bitbucket 上为我的“引擎”存储库构建和测试拉取请求。我正在使用 Bitbucket Pull Request Builder 插件,该插件检查 PR 分支,对目标分支进行本地合并(使用“构建前合并”管道附加行为),然后在我的 Jenkinsfile 中执行管道。
这些测试具有一些存储在其他存储库中的依赖项。我的 Jenkinsfile 将它们签入子目录(我也尝试将它们签入父目录中的新目录,而不是作为子目录)。
node {
dir('tools') { git url: 'ssh://git@bitbucket.org:<my_org>/tools.git', branch: 'master', credentialsId: 'my-cred-id' }
}
Run Code Online (Sandbox Code Playgroud)
当此工具签出步骤发生时,git 插件会尝试签出“tools”目录中“engine”存储库的 HEAD 提交:
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url git@bitbucket.org:<my_org>/engine.git # timeout=10
Fetching upstream changes from git@bitbucket.org:<my_org>/engine.git
> git --version # timeout=10
using GIT_SSH to set credentials <creds>
> git fetch --tags --progress git@bitbucket.org:<my_org>/engine.git +refs/heads/*:refs/remotes/origin/* …
Run Code Online (Sandbox Code Playgroud)