Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
Why this simple export is giving me error in nodejs?

I got this example product js file and i am exporting it and using it in the node routes

let products = [
    {
      _id: "1",
      name: "Airpods Wireless Bluetooth Headphones",
    },
    {
      _id: "2",
      name: "iPhone 11 Pro 256GB Memory",
    },
    {
      _id: "3",
      name: "Cannon EOS 80D DSLR Camera",
    },
  ];
  
  export default products

and i am getting that data in the server.js like this

const products = require('./data/products')

const app = express()

app.get('/', (req, res) => {
    res.json('api running')
})

app.get('/api/products', (req, res) => {
    res.json(products)
})


app.get("/api/products/:id", (req, res) => {
    const product = products.filter(p => p._id === req.params.id);
     res.json(product);
});

but whenever i try to run the server i got this error Unexpected token 'export'. Why this simple export is giving me error?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use common js module syntax instead of es6 module syntax for exporting products:

module.exports = products;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!