I am writing a small test code in an ExpressJs app. The code is as follows :
var express = require('express');
var app = express();
var dataFile = require('./data/data.json');
app.set('port', process.env.PORT || 3000);
app.get('/', function(req, res) {
var info = '';
dataFile.speakers.forEach(function(item) {
info += `<li>
<h2>${item.name}</h2>
<p>${item.summary}</p>
</li>
`;
});
res.send(`
<h1>My Meetups</h1>
${info}
`);
});
var server = app.listen(app.get('port'), function() {
console.log('Listening on port ' + app.get('port'));
});
When I try to execute the command
node app/app.js
in Git bash terminal, I get the following error :
> E:\expressjs\app\app.js:11
> info += `<li>
> ^ SyntaxError: Unexpected token ILLEGAL
> at Module._compile (module.js:439:25)
> at Object.Module._extensions..js (module.js:474:10)
> at Module.load (module.js:356:32)
> at Function.Module._load (module.js:312:12)
> at Function.Module.runMain (module.js:497:10)
> at startup (node.js:119:16)
> at node.js:935:3
What I tried :
Am using the Atom Editor
What I suspect : Incompatible version of Node and ECMA
Can someone help with this ?
Thanks
Try this site. It shows all es6 features implemented in nodeJS
My suspect is that you using very old version of node(almost all features gives error in node 0.10).
Try to upgrade into node6 and all should be OK.
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.