【问题标题】:typeerror undefined is not a function in node jstypeerror undefined 不是节点 js 中的函数
【发布时间】:2017-09-29 23:37:03
【问题描述】:

我有一个简单的表格,它给了我以下错误。 TypeError: undefined is not a function on line no 20. 请帮帮我

var path = require('path')
var funcs = require('./funcs')
var encodeName = funcs.encodName

var session = {
  username: process.argv[2],
  lastMessageHash: process.argv[3]
}

if (!session.username || !session.lastMessageHash) {
  console.log('Usage: node index.js <username> <hash>')
  process.exit(0)
}

// 1. load the database
var dbFile = path.join(__dirname, 'db', 'index.json')
funcs.loadDb(dbFile, function (err, db) {

  // 2. encode the name
  var encoded = encodeName(session.usrename) // error line no 20

  // 3. find the user's inbox
  var inbox = funcs.findInbox(db, encoded)

  // 4. find the next message
  var nextMessage = funcs.findNextMessage(inbox, session.lastMessageHash)

  // 5. print out the message.
  // Paste the console output into the "Solution" field and you're done!
  console.log(nextMessage)
})

我正在我的节点 js 项目上处理带有数据库连接的简单页面。我是nodejs的新手。

【问题讨论】:

  • 如何从 func 文件中导出 funcs.encodName?问题一定是存在的。甚至显示整个 func.js 文件。谢谢。
  • @patel 请不要删除您发布的问题。它可能会让那些试图帮助你的人感到沮丧。如果你已经解决了,那就给它一个答案。

标签: javascript jquery node.js


【解决方案1】:

我不能确定为什么它不起作用,因为我不知道./funcs 的内容,但是第 3 行和第 20 行有错别字,所以可能是因为错字它没有找到合适的功能。你最好更仔细地检查你的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-27
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 2020-11-24
    • 2017-07-28
    • 1970-01-01
    相关资源
    最近更新 更多