繁体   English   中英

语法错误-意外标识符(带有节点的XMPP)

[英]Syntax Error - unexpected identifier (XMPP with Node)

语法错误-带有节点的意外标识符XMPP

我是Node和XMPP的新手,使用ltx读取聊天节时出现错误,错误是:。

const logEntry = 'Received message from ' ${from} ' with ^ SyntaxError: Unexpected identifier

at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:390:7) at startup (bootstrap_node.js:150:9)

文件名是:index.js

这是代码:

    const Client = require('node-xmpp-client')
, ltx = Client.ltx
const options = {
jid: 'bot@localhost',
password: 'tellnoone'
}
const client = new Client(options)
client.on('online', (connectionDetails) => {
console.log('We are connected!')
console.log(connectionDetails)
sendPresence()
})
const sendPresence = () => {
var stanza = new ltx.Element('presence')
console.log('Sending presence: ' + stanza.toString())
client.send(stanza)
}
client.on('stanza', (stanza) => {
if (false === stanza.is('message')) return /* Not a <message/> stanza */
const messageContent = stanza.getChildText('body')
if (!messageContent) return /* Not a chat message */
const from = stanza.attr('from')
const logEntry = 'Received message from ' ${from} ' with
content:\n${messageContent}'
console.log(logEntry)
})

尝试换线

const logEntry = 'Received message from ' ${from} ' with content:\\n${messageContent}'

const logEntry = `Received message from ${from} with content:\\n ${messageContent}`

模板字符串使用反引号代替引号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM