节点服务器无法启动

节点服务器无法启动

本文介绍了节点服务器无法启动,提供了意外的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我尝试启动服务器时,都会出现一个很长的错误:

Every time I try to start my server it gives me a long error:

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/ubuntu/workspace/isal/routes/index.js:5:15)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

语法错误的文件是此index.js文件,它声称存在解析错误,最后一行带有意外的令牌,但意外的令牌后没有任何内容,我真的看不到模块导出的问题

The file with the syntax error is this index.js file It claims that there is a parsing error, unexpected token with the final line, but has nothing after unexpected token and I don't really see the problem with the module exporting.

var express = require('express');
var router = express.Router();
var imgur = require('../services/imgur');

router.get('/', function(req, res) {
  res.send('Hello');
});

router.get('/latest', function(req, res) {

});

router.get('/search/:q', function(req, res) {
    imgur.getImage(req.params.q, req.query.offset).then(ans => {
        res.json(ans);
});

module.exports = router;

推荐答案

您没有正确关闭最终函数调用:

you are not properly closing your final function call:

var express = require('express');
var router = express.Router();
var imgur = require('../services/imgur');

router.get('/', function(req, res) {
  res.send('Hello');
});

router.get('/latest', function(req, res) {

});

router.get('/search/:q', function(req, res) {
    imgur.getImage(req.params.q, req.query.offset).then(ans => {
        res.json(ans);
    }); <---------------- Missing
});

module.exports = router;

当您收到这样的语法错误时,它基本上意味着从发生错误的地方开始,并在文件中回溯直到找到语法错​​误.如果抛出语法错误,则总是.您应该使用一种工具来突出显示语法,并为自己节省很多问题,例如IDE.

When you get a syntax error like this, it basically means start from where the error occurred, and backtrack up in your file until you find the syntax error. There will always be a syntax error, if a syntax error is thrown. You should be using a tool to code with syntax highlighting and save yourself a world of problems, like an IDE.

这篇关于节点服务器无法启动,提供了意外的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:48