repl node js问题SyntaxError:意外的标识符

时间:2018-09-12 15:50:26

标签: javascript html node.js mongodb express

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)

1 个答案:

答案 0 :(得分:0)

我浏览了原始的server.js文件,发现您在第12行上缺少分号,即db = database.db("api");

  

更新

我刚刚意识到,repl NodeJs演示是使用index.js文件触发的。我只是在server.js中导出一个函数,然后将其导入index.js中,以触发服务器创建过程。

选中the updated poc

希望它能起作用!