SyntaxError: Unexpected token "const"

I am getting this error in my terminal :
SyntaxError: Unexpected token “const”

My code in app.js is this :

app.post("/", function(req, res
   const post = {
    title: req.body.postTitle,
    content: req.body.postBody
  };
  posts.push(post);
  res.redirect("/");
});

What should I do

I assume you’re using a really old version of Node? can you type node --version into the terminal to check?

Welcome, webgikk.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums

To answer your question: Give this a read: https://www.freecodecamp.org/news/how-to-enable-es6-and-beyond-syntax-with-node-and-express-68d3e11fe1ab/

function(req, res) {

I think this is at fault.

The callback function is malformed. You need to close the function parameter list () and you need to have the opening function body bracket {.

app.post("/", function(req, res) {
  const post = {
   title: req.body.postTitle,
   content: req.body.postBody
 };
 posts.push(post);
 res.redirect("/");
});

Thanks a lot. You were right , I didn’t close the function parameter list and didn’t have the opening function body bracket. After 8 hours of code, such simple things become hard to spot.

Thanks a lot! My first time here :grinning: