Brian J Brian J - 1 month ago 12
Node.js Question

Why does eslint throw an error on a require statement?

I've created a utility class via module.exports that uses SSPI package to get a user's NT name.

So far the class just requires

express
and
node-sspi
packages. Then an authenticate function invokes a request to get the user's NT name.

But when I build the solution this utility class throws an
eslint error
on line 3 where my first require assignment is defined:

var express = require('express');


Question:

Why does eslint throw an error on a require statement?

The detail of the error is as follows:

Message:
Parsing error: Unexpected token, expected ,
Details:
fileName: src\js\util\requestLDAP.js
lineNumber: 3


This is the gist of my utility class:

module.exports = {

var express = require('express');
var nodeSSPI = require('node-sspi');

var nodeSSPIObj = new nodeSSPI({
retrieveGroups: true
}),

authenticate: function () {
nodeSSPIObj.authenticate(req, res, function(err){
var ntUser = req.connection.user;
})
},
}

Answer

You don't need to use var inside an object literal to define properties.

var nodeSSPI = require('node-sspi');
var nodeSSPIObj = new nodeSSPI({ retrieveGroups: true });

module.exports = {
  express: require('express'),
  nodeSSPI: nodeSSPI,
  nodeSSPIObj: nodeSSPIObj,
  authenticate: function () {
    nodeSSPIObj.authenticate(req, res, function(err){
      var ntUser = req.connection.user;
    })
  }
}