'Facing problem on importing express from express

I am working on MERN app and while importing express it is showing error it shows SyntaxError: Cannot use import statement outside a module my code is

import express from 'express';

const app = express();
const port = process.env.PORT || 3000;

app.get('/',(req,res)=>{
    res.send('this is homepage')
})

app.listen( port ,()=>{
    console.log('server is running at port number 3000')
});


Solution 1:[1]

when you work with nodejs, you should use this syntax instead of import '...' from '....':

const express = require('express')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1