I am just trying to setup a crud on node.js with mongodb. I am new and kind of following a tutorial.
getting the below error that seems unsolvable
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
here is my index.js
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var mongodb = require('mongodb');
var app = express();
var port = 3000;
app.get('/',(req,res)=>{res.send('hi')});
app.listen(port,()=> {console.log('server live @ '+port)});
here is my package.json
{
"name": "nodementor",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "krishna",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongodb": "^3.6.0"
}
}
So far tried adding "type": "module", in package.json which again gives out another error
(node:3680) ExperimentalWarning: The ESM module loader is experimental.
file:///D:/MEAN/nodementor/index.js:1
SyntaxError: Invalid or unexpected token
at Loader.moduleStrategy (internal/modules/esm/translators.js:122:18)
at async link (internal/modules/esm/module_job.js:42:21)