Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SyntaxError:意外标识符-express.js_Javascript - Fatal编程技术网

Javascript SyntaxError:意外标识符-express.js

Javascript SyntaxError:意外标识符-express.js,javascript,Javascript,我使用express.js const express = require('express') const app = express() var bodyParser = require('body-parser'); var cors = require('cors'); app.use(cors()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));

我使用
express.js

const express  = require('express')
const app      = express()
var bodyParser = require('body-parser');
var cors       = require('cors');

app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(function(req, res, next) {
   res.header("Access-Control-Allow-Origin", "*");
   res.header('Access-Control-Allow-Methods', 'DELETE, PUT');
   res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
   next();
});

app.post('/api/v1/login.json', function (req, res) {
  var user = login(req.body.email, req.body.password)

  if user !== null {
    res.status(200).json({token: "test_token"});
  } else {
    res.status(401).json({error: 'Niepoprawny email lub hasło.'});
  }
})

app.listen(3000, function () {
  console.log('server listening on port 3000')
})

const users = [
  {
    id: 1,
    email: 'test@user.com',
    password: 'password',
    access_token: 'test_user_access_token'
  },

  {
    id: 2,
    email: 'second@user.com',
    password: 'password',
    access_token: 'second_user_access_token'
  }
]

function login(email, password) {
  return users.find(x => x.email === email && x.password === password);
}
当我尝试运行它时,它返回以下错误:

  if user !== null {
     ^^^^
SyntaxError: Unexpected identifier

如何解决此问题?

if语句的正确语法为:

if (user !== null) {
    ...

基本javascript语法:

if (user !== null) {

因为这不是你如何做对不起,但我会考虑这个话题,因为它是一个简单的键入。可能的复制的@ EngReXxBox否,但我认为这是最接近不查语法的<代码>如果< /COD>它给出了<代码>语法错误< /代码>,然后问这样?我真的在问,因为我认为这是离题的,但这对我来说是最接近的。