I am using node.js v18.17.0
I have set in package.json that "type": "module"
I use import http from 'http'
which doesn’t give me any error
However, if I try to use export like:
function renderStatus(url){
var arr = ["/home", "/list"]
return arr.includes(url)?200:404
}
export renderStatus
It gives me the following error:
SyntaxError: Unexpected token 'export'
Can anyone explain why this is happening?
Thanks a lot!
2
Answers
As Being Shame said,
export {renderStatus}
should be the correct syntax.We can also
export function renderStatus(url){...}
to export a function.Read more here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
Use Can Fix It By Either Of These;
export default renderStatus
(if this is the only export from the concerning file)export { renderStatus, export2, export3....}
(in case of multiple exports from the concerning file)