我正在使用meteor 1.4.2.3并且我想导入NodeJs网络模块?我试图在服务器端使用import net from 'net';
导入它,但这不起作用。网络未定义。
import net from 'net';
export class Print {
private printAsync(callback){
let client = new net.Socket();
}
}
答案 0 :(得分:0)
从一个新的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
。