Nizamuddin Shaikh
Nizamuddin Shaikh

Reputation: 420

Getting error in node

I am new to MEAN and interested in self learning node.js and express.js. I have installed npm and related modules but on running my code I am getting an error message which I cannot understand.

My code is as under:

var express = require('express');
var app express();
var myPort = 1117;

app.set('port', myPort);



app.get('/',

  function(req, res)
  {
    res.send(<h1>This is express!</h1>); 
    console.log("Express started at port no " + myPort);
  }

)

app.listen(myPort);

The name of file is prj.js When is give command node prj.js The error displayed is as under:

G:\JavaPrgsJGD\Nodejs_My\prgs>node prj.js
G:\JavaPrgsJGD\Nodejs_My\prgs\prj.js:2
var app express();
    ^^^^^^^

SyntaxError: Unexpected identifier
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 Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3

Upvotes: 1

Views: 32

Answers (1)

gelliott181
gelliott181

Reputation: 1028

var app express(); is not valid JavaScript. You meant var app = express();.

Upvotes: 2

Related Questions