i have created the file(index.js) which should connect to the Mongo db , The file code is below
but when when i am trying to run the file by typring node index.js it is giving me the error
C:\Users\MOHAS076\SBC-trp-web-test-automation\node_modules\mongodb\lib\bson.js:10
catch { } // eslint-disable-line
^
SyntaxError: Unexpected token {
CODE -
// Module calling
MongoClient = require ('mongodb');
// Server path
const url = 'mongodb://10.142.206.22:27017/';
// Name of the database
const dbname = 'snapp_transactions';
MongoClient.connect (url, (err, client)=>{
if (!err) {
log.info ('successful connection with the server');
}
else
{ log.info ('Error in the connectivity'); }
});
The things what i have tried to resolve
- reinstalling my node module.
- reinstalling mongodb after deleting . 3 commenting the line const bson_1 = require("./bson"); which is present in the utils.js , but after that it is giving error 'mongodb' not found .
this is below my package.json ( where my "mongodb": "^4.1.0" is that due to compatibility issue , my node version is 8.12 as per the project requirement )
{
"name": "sbcwdwdlr-web-test-automation",
"version": "1.0.0",
"private": true,
"description": "This package contains an example of implementing GQE's Node.js test framework for mobile using Cucumber and Mocha.",
"keywords": [
"gqe",
"mobile",
"node",
"webdriverio"
],
"license": "UNLICENSED",
"author": "James T. Wood",
"main": "wdio.cucumber.conf",
"scripts": {
"build": "npm run clean:dist && npm run lint && npm run build:ts && npm run format",
"build:ts": "tsc -p .tsconfig.json",
"clean:dist": "rm -R ./dist || true",
"format": "prettier --write \"dist/**/*.{js,json}\" || true",
"lint": "npm run lint:js && npm run lint:ts && npm run lint:gherkin",
"lint:js": "eslint . || true",
"lint:ts": "tslint -c .tslint.json -p .tsconfig.json || true",
"lint:gherkin": "gherkin-lint --rulesdir \"src/utilities/build/gherkin-rules\" || true",
"test": "npm run test:all",
"test:all": "cross-env TS_NODE_PROJECT=.tsconfig.json mocha -r ts-node/register test/**/*.spec.ts"
},
"dependencies": {
"@gqe/cli": "*",
"@gqe/framework-core": "^2.0.30",
"@gqe/framework-cucumber": "^2.0.43",
"@gqe/framework-entities": "^2.0.44",
"@gqe/framework-services": "^2.0.44",
"@gqe/framework-utilities": "^2.0.28",
"@gqe/framework-web": "^2.0.30",
"@gqe_mslt/common": "git+ssh://git@github.disney.com:MSLT/mslt-common.git#v1.4.3",
"@types/redis": "^2.8.25",
"deepmerge": "^2.2.1",
"dotenv": "^6.2.0",
"dotenv-json": "^1.0.0",
"inquirer": "^6.2.1",
"jimp": "^0.16.1",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.20",
"loglevel": "^1.6.1",
"minimist": "^1.2.0",
"moment": "^2.23.0",
"mongodb": "^4.1.0",
"randomstring": "^1.1.5",
"redis": "^2.8.0",
"redis-cli": "^1.3.1",
"unique-names-generator": "^3.0.0",
"uuid": "^8.3.1",
"window": "^4.2.7",
"xml-js": "^1.6.11"
},
"devDependencies": {
"@types/chai": "^4.1.4",
"@types/deepmerge": "^2.1.0",
"@types/dotenv": "^4.0.3",
"@types/inquirer": "0.0.42",
"@types/lodash": "^4.14.119",
"@types/minimist": "^1.2.0",
"@types/mocha": "^5.2.4",
"@types/node": "^10.12.18",
"@types/prettier": "^1.15.2",
"chai": "^4.1.2",
"cross-env": "^7.0.2",
"eslint": "^5.10.0",
"gherkin-lint": "^2.13.2",
"mocha": "^5.2.0",
"node-fetch": "^2.6.1",
"node-key-sender": "^1.0.11",
"prettier": "1.13.7",
"reports": "^0.1.1",
"ts-node": "^7.0.0",
"tslint": "^5.12.0",
"tslint-eslint-rules": "^5.3.1",
"typescript": "^3.6.3",
"wdio-multiple-cucumber-html-reporter": "^1.1.1"
}
}