使用快速创建服务器为网络挂接 - 设置错误 - 无效的或意外的标记

问题描述 投票:-1回答:2

我想了解Facebook的消息机器人,因为我认为他们是整齐的。我一直在关注this Medium article这是一个教程,我已经得到了,你叫index.js的一部分。

节点index.js

const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(3000, () => console.log('Webhook server is listening, port 3000'));

当我这样做,我收到一个错误,说明我有一个意外的标记。我不知道如何对其做出反应。

JSON文件:

    {
  "name": "bot-tutorial",
  "version": "1.0.0",
  "description": "My first bot",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.4"
  }
}

我收到的错误:

C:\Users\jackt\Bot Tutorial\index.js:2
const app = express();
            ^

ReferenceError: express is not defined
    at Object.<anonymous> (C:\Users\jackt\Bot Tutorial\index.js:2:13)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

目录结构:

javascript
2个回答
0
投票

在index.js可以包括

const express = require('express');

1
投票

你可能已复制从文章的代码与卷曲的单引号一起:

他们更改为普通的单引号:'

© www.soinside.com 2019 - 2024. All rights reserved.