Home Fat arrow function throwing error "expression expected"
Reply: 3

Fat arrow function throwing error "expression expected"

Ryder Thacker
1#
Ryder Thacker Published in 2018-01-12 15:37:01Z

I am setting up my server.js file in angular following a tutorial. In the tutorial he has no errors while my fat arrow funtion is saying "expression expected". I am new to javascript and mainly know Java.

server.js

var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var http = require(http);
var app = express();

var api = require('./server'/api);

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

app.use(express.static(path.join(__dirname, 'dist')));

app.use('/', api);

app.get('*'), (req, res) => {
  res.sendFile(path.join(__dirname, "dist/index.html"));
}

var port = precess.env.PORT || '3000';
app.set('port', port);

var server = http.createServer(app);
server.listen(port, () => console.log("Server is running"));
Ryder Thacker
2#
Ryder Thacker Reply to 2018-01-12 17:12:12Z

You need to remove the bracket here

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, "dist/index.html"));
}

Also you need to reposition your quote mark here to be at the end of the string

var api = require('./server/api');

Also, which version of node are you using, as there is a chance arrow functions are not supported?

Geraint
3#
Geraint Reply to 2018-01-12 15:46:51Z

I can see you've got a few errors:

var http = require(http); should be var http = require('http');

var api = require('./server'/api); should be var api = require('./server/api');

(both missing ')

var port = precess.env.PORT || '3000'; should be var port = process.env.PORT || '3000'; (typo in process)

and, app.get(... should be

app.get('*', (req, res) => { res.sendFile(path.join(__dirname, "dist/index.html")); })

(the end bracket is in the wrong place)

Diego Lievano
4#
Diego Lievano Reply to 2018-01-12 15:49:19Z

You have an error on the port property:

var port = precess.env.PORT || '3000';

change it to

var port = process.env.PORT || '3000';

Change the word precess to process.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336738 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO