- 我正在尝试学习 node js。
- 所以我使用了下面的示例并在 repl 中实现。 https://medium.freecodecamp.org/building-a-simple-node-js-api-in-under-30-minutes-a07ea9e390d2
- 但我无法运行该应用程序。
- 当我运行应用程序时出现以下错误。
- 你能告诉我如何解决吗?
- 在下面提供我的代码库。
- 有没有在线编辑器可以让我运行node js看看
https://repl.it/@doadhdoadh/IdleAccurateSource
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const app = express();
const port = 8000;
app.use(bodyParser.urlencoded({ extended: true }));
require('./app/routes')(app, {});
app.listen(port, () => {
console.log('We are live on ' + port);
});
node v9.7.1 linux/amd64
npm dev
evalmachine.<anonymous>:1
npm dev
^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInContext (vm.js:181:10)
at evaluate (/run_dir/repl.js:133:14)
at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
at ReadStream.emit (events.js:180:13)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at ReadStream.Readable.push (_stream_readable.js:218:10)
at fs.read (fs.js:2124:12)
最佳答案
我查看了原始 server.js
文件,发现第 12 行缺少分号,即 db = database.db("api");
Update
我刚刚意识到 repl NodeJs 演示是使用 index.js 文件触发的。我刚刚在 server.js 中导出了一个函数并将其导入到 index.js 中以触发服务器创建过程。
希望它有用!
关于javascript - repl Node js问题SyntaxError : Unexpected identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52299130/