從一個新鮮的meteor create
項目,以下適用於我。
在/server/main.js
:
import { Meteor } from 'meteor/meteor';
Meteor.startup(() => {
// code to run on server at startup
});
import net from 'net';
export class Print {
printAsync(callback){
let client = new net.Socket();
console.log(client);
}
}
console.log(net);
const print = new Print();
print.printAsync();
輸出在控制檯:
I20161129-07:59:18.007(-8)? { createServer: [Function],
I20161129-07:59:18.008(-8)? createConnection: [Function],
I20161129-07:59:18.008(-8)? connect: [Function],
I20161129-07:59:18.008(-8)? _normalizeConnectArgs: [Function: normalizeConnectArgs],
I20161129-07:59:18.008(-8)? Socket: { [Function: Socket] super_: { [Function: Duplex] super_: [Object] } },
I20161129-07:59:18.008(-8)? Stream: { [Function: Socket] super_: { [Function: Duplex] super_: [Object] } },
I20161129-07:59:18.009(-8)? Server:
I20161129-07:59:18.009(-8)? { [Function: Server]
[...]
I20161129-07:59:18.012(-8)? Socket {
I20161129-07:59:18.013(-8)? _connecting: false,
I20161129-07:59:18.013(-8)? _hadError: false,
I20161129-07:59:18.013(-8)? _handle: null,
I20161129-07:59:18.013(-8)? _parent: null,
I20161129-07:59:18.013(-8)? _host: null,
I20161129-07:59:18.013(-8)? _readableState:
I20161129-07:59:18.020(-8)? ReadableState {
I20161129-07:59:18.020(-8)? objectMode: false,
I20161129-07:59:18.020(-8)? highWaterMark: 16384,
[...]
我無法重現您不確定net
。
我正在導入它在服務器端,但導入不起作用。 –
呵呵,它適合我。你有樣品回購還是你能提供更多的上下文? – kooc
我更新了問題。變量網絡是未定義的。你是如何導入網絡模塊的?你安裝了npm包嗎? –