如何在node.js中停用express server信息日志?

如何在node.js中停用express server信息日志?,node.js,express,http,Node.js,Express,Http,我正在尝试在replit.com上用node.js托管一个简单的express服务器,到目前为止,它运行得相当好。但是,每当我启动应用程序时,都会出现一些非常烦人的控制台输出: Server { insecureHTTPParser: undefined, _events: [Object: null prototype] { connection: [Function: connectionListener], close: [Function: bound close

我正在尝试在replit.com上用node.js托管一个简单的express服务器,到目前为止,它运行得相当好。但是,每当我启动应用程序时,都会出现一些非常烦人的控制台输出:

Server {
  insecureHTTPParser: undefined,
  _events: [Object: null prototype] {
    connection: [Function: connectionListener],
    close: [Function: bound close],
    listening: [ [Function: bound init], [Function] ],
    upgrade: [Function],
    request: [Function]
  },
  _eventsCount: 5,
  _maxListeners: undefined,
  _connections: 0,
  _handle: TCP {
    reading: false,
    onconnection: [Function: onconnection],
    [Symbol(owner_symbol)]: [Circular]
  },
Server {
  insecureHTTPParser: undefined,
  _events: [Object: null prototype] {
    request: [Function: app] EventEmitter {
      _events: [Object: null prototype],
      _eventsCount: 1,
      _maxListeners: undefined,
      setMaxListeners: [Function: setMaxListeners],
      getMaxListeners: [Function: getMaxListeners],
      emit: [Function],
      addListener: [Function: addListener],
      on: [Function: addListener],
      prependListener: [Function: prependListener],
      once: [Function: once],
      prependOnceListener: [Function: prependOnceListener],
      removeListener: [Function: removeListener],
      off: [Function: removeListener],
      removeAllListeners: [Function: removeAllListeners],
      listeners: [Function: listeners],
      rawListeners: [Function: rawListeners],
      listenerCount: [Function: listenerCount],
      eventNames: [Function: eventNames],
      init: [Function: init],
      defaultConfiguration: [Function: defaultConfiguration],
      lazyrouter: [Function: lazyrouter],
      handle: [Function: handle],
      use: [Function: use],
      route: [Function: route],
      engine: [Function: engine],
      param: [Function: param],
      set: [Function: set],
      path: [Function: path],
      enabled: [Function: enabled],
      disabled: [Function: disabled],
      enable: [Function: enable],
      disable: [Function: disable],
      acl: [Function],
      bind: [Function],
      checkout: [Function],
      connect: [Function],
      copy: [Function],
      delete: [Function],
      get: [Function],
      head: [Function],
      link: [Function],
      lock: [Function],
      'm-search': [Function],
      merge: [Function],
      mkactivity: [Function],
      mkcalendar: [Function],
      mkcol: [Function],
      move: [Function],
      notify: [Function],
      options: [Function],
      patch: [Function],
      post: [Function],
      pri: [Function],
      propfind: [Function],
      proppatch: [Function],
      purge: [Function],
      put: [Function],
      rebind: [Function],
      report: [Function],
      search: [Function],
      source: [Function],
      subscribe: [Function],
      trace: [Function],
      unbind: [Function],
      unlink: [Function],
      unlock: [Function],
      unsubscribe: [Function],
      all: [Function: all],
      del: [Function],
      render: [Function: render],
      listen: [Function: listen],
      request: [IncomingMessage],
      response: [ServerResponse],
      cache: {},
      engines: {},
      settings: [Object],
      locals: [Object: null prototype],
      mountpath: '/',
      _router: [Function]
    },
    connection: [Function: connectionListener],
    listening: [Function: bound onceWrapper] { listener: [Function] }
  },
  _eventsCount: 3,
  _maxListeners: undefined,
  _connections: 0,
  _handle: TCP {
    reading: false,
    onconnection: [Function: onconnection],
    [Symbol(owner_symbol)]: [Circular]
  },
  _usingWorkers: false,
Server {
  insecureHTTPParser: undefined,
  _events: [Object: null prototype] {
    request: [Function: app] EventEmitter {
      _events: [Object: null prototype],
      _eventsCount: 1,
      _maxListeners: undefined,
      setMaxListeners: [Function: setMaxListeners],
      getMaxListeners: [Function: getMaxListeners],
      emit: [Function],
      addListener: [Function: addListener],
      on: [Function: addListener],
      prependListener: [Function: prependListener],
      once: [Function: once],
      prependOnceListener: [Function: prependOnceListener],
      removeListener: [Function: removeListener],
      off: [Function: removeListener],
      removeAllListeners: [Function: removeAllListeners],
      listeners: [Function: listeners],
      rawListeners: [Function: rawListeners],
      listenerCount: [Function: listenerCount],
      eventNames: [Function: eventNames],
      init: [Function: init],
      defaultConfiguration: [Function: defaultConfiguration],
      lazyrouter: [Function: lazyrouter],
      handle: [Function: handle],
      use: [Function: use],
      route: [Function: route],
      engine: [Function: engine],
      param: [Function: param],
      set: [Function: set],
      path: [Function: path],
      enabled: [Function: enabled],
      disabled: [Function: disabled],
      enable: [Function: enable],
      disable: [Function: disable],
      acl: [Function],
      bind: [Function],
      checkout: [Function],
      connect: [Function],
      copy: [Function],
      delete: [Function],
      get: [Function],
      head: [Function],
      link: [Function],
      lock: [Function],
      'm-search': [Function],
      merge: [Function],
      mkactivity: [Function],
      mkcalendar: [Function],
      mkcol: [Function],
      move: [Function],
      notify: [Function],
      options: [Function],
      patch: [Function],
      post: [Function],
      pri: [Function],
      propfind: [Function],
      proppatch: [Function],
      purge: [Function],
      put: [Function],
      rebind: [Function],
      report: [Function],
      search: [Function],
      source: [Function],
      subscribe: [Function],
      trace: [Function],
      unbind: [Function],
      unlink: [Function],
      unlock: [Function],
      unsubscribe: [Function],
      all: [Function: all],
      del: [Function],
      render: [Function: render],
      listen: [Function: listen],
      request: [IncomingMessage],
      response: [ServerResponse],
      cache: {},
      engines: {},
      settings: [Object],
      locals: [Object: null prototype],
      mountpath: '/',
      _router: [Function]
    },
    connection: [Function: connectionListener],
    listening: [Function: bound onceWrapper] { listener: [Function] }
  },
  _eventsCount: 3,
  _maxListeners: undefined,
  _connections: 0,
  _handle: TCP {
    reading: false,
    onconnection: [Function: onconnection],
    [Symbol(owner_symbol)]: [Circular]
  },
  _usingWorkers: false,
Server {
  insecureHTTPParser: undefined,
  _events: [Object: null prototype] {
    connection: [Function: connectionListener],
    close: [Function: bound close],
    listening: [ [Function: bound init], [Function] ],
    upgrade: [Function],
    request: [Function]
  },
  _eventsCount: 5,
  _maxListeners: undefined,
  _connections: 0,
  _handle: TCP {
    reading: false,
    onconnection: [Function: onconnection],
    [Symbol(owner_symbol)]: [Circular]
  },
  _usingWorkers: false,
  _workers: [],
  _unref: false,
  allowHalfOpen: true,
  pauseOnConnect: false,
  httpAllowHalfOpen: false,
  timeout: 120000,
  keepAliveTimeout: 5000,
  maxHeadersCount: null,
  headersTimeout: 60000,
  _connectionKey: '6::::800',
  [Symbol(IncomingMessage)]: [Function: IncomingMessage],
  [Symbol(ServerResponse)]: [Function: ServerResponse],
  [Symbol(kCapture)]: false,
  [Symbol(asyncId)]: 4
}
这是我的密码:

const fs = require("fs");

const express = require('express');
const app = express();
const server = require('http').createServer(app);

app.get('/', (req, res) => {
  res.setHeader('Content-type','text/html');
  res.write(fs.readFileSync(__dirname + '/index.html'));
  res.end();
});

app.get("/pages/:page", (req, res) => {
  let page = req.params.page;
  res.setHeader('Content-type','text/html');
  res.write(fs.readFileSync(`${__dirname}/pages/${page}.html`));
  res.end();
})

server.listen(800, () => {
  console.log('listening on *:800');
});

如何停用此功能?我不想禁用console.log()本身。我相信我不久前也遇到过同样的问题,但我记不起修复的方法了——如果它不是我偶然修复的。我试图删除代码的不同部分,但运气不佳,我也无法在网上找到任何类似的问题。

这是由于replit.com将命令结果回显到控制台造成的

一个简单的解决方法如下:

const fs = require("fs");

const express = require('express');
const app = express();
const server = require('http').createServer(app);


let {} = app.get('/', (req, res) => {
  res.setHeader('Content-type','text/html');
  res.write(fs.readFileSync(__dirname + '/index.html'));
  res.end();
});

let {} = app.get("/pages/:page", (req, res) => {
  let page = req.params.page;
  res.setHeader('Content-type','text/html');
  res.write(fs.readFileSync(`${__dirname}/pages/${page}.html`));
  res.end();
})

let {} = server.listen(80, () => {
  console.log('listening on *:80');
});
这是
app.get
server.listen
调用返回的服务器对象(然后记录)

replit.com中应该有一些配置来查找并更改此设置(例如,不要将命令结果回显到控制台),我还没有找到它,但这可能是一个更好的修复方法