I have a console bug. please help
Mongo is not defined - problem while loading data from the server
C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\utils.js:123
process.nextTick(function() { throw err; });
ReferenceError: mongo is not defined
at C:\Users\Robert\Desktop\FINISH\routes\info.js:38:70
at C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:122:13
at _each (C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:46:13)
at Object.async.each (C:\Users\Robert\Desktop\FINISH\node_modules\async\lib\async.js:121:9)
at C:\Users\Robert\Desktop\FINISH\routes\info.js:34:31
at handleCallback (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\utils.js:120:56)
at C:\Users\Robert\Desktop\FINISH\node_modules\mongodb\lib\cursor.js:861:16
at handleCallback (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:171:5)
at setCursorDeadAndNotified (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:505:3)
at nextFunction (C:\Users\Robert\Desktop\FINISH\node_modules\mongodb-core\lib\cursor.js:660:7)
package.json:
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^0.9.0",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.10.2",
"bson": "^4.2.2",
"client-sessions": "^0.7.0",
"express": "^4.11.1",
"express-handlebars": "^2.0.1",
"mongodb": "^2.2.33"
}
}
Line 38 of info.js references mongo: mongo.ObjectID..., but mongo does not exist in that file. You need to add const mongo = require('mongodb') to the top of the file along with your require of the async module. And for future reference, you can edit posts on StackOverflow rather than replying with detail as an answer.
Related
My nodejs script was working perfectly fine the other day and now I'm getting this abort signal error below. The code is literally copied verbatim from the serpapi site. I had my own code that's slightly different but I get the same error even when just using the site's sample code. https://serpapi.com/google-lens-api. It seems to be a local issue because when I ran it standalone on Replit it seemed to be fine. My package json is below as well.
import { getJson } from "serpapi";
const params = {
url: "https://i.imgur.com/HBrB8p0.png",
api_key: "{xxx}"
};
// Show result as JSON
const response = await getJson("google_lens", params);
console.log(response["visual_matches"]);
"name": "cheerio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#google-cloud/vision": "^3.1.1",
"axios": "^1.3.2",
"cheerio": "^1.0.0-rc.12",
"jimp": "^0.22.4",
"node-fetch": "^3.3.0",
"openai": "^3.1.0",
"serpapi": "^1.1.0"
signal: AbortSignal.timeout(timeout),
^
ReferenceError: AbortSignal is not defined
I am having an issue with my ExpressJS app using sequelize. When I run the app, I get this message:
node:internal/modules/cjs/loader:488
throw e;
^
Error: Cannot find module
'C:\node_projects\my_app\node_modules\sequelize\dist\lib\table-hints'
This issue started happening after I edited one of my app's routes, which has nothing to do with app initialization. I cannot share code, because it seems to be a problem within sequelize itself.
My package.json looks like this:
{
"name": "my_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"client": "npm run start --prefix client",
"dexy": "concurrently \"npm start\" \"npm run client\" ",
"test": "node_modules/.bin/mocha tests.js --timeout 10000"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"bluebird": "^3.7.2",
"body-parser": "^1.19.1",
"cookie-session": "^2.0.0",
"ejs": "^3.1.6",
"express": "^4.17.2",
"express-validation": "^3.0.8",
"express-validator": "^6.14.0",
"helmet": "^4.6.0",
"joi": "^17.5.0",
"mailgun-js": "^0.22.0",
"moment": "^2.29.1",
"morgan": "^1.10.0",
"passport": "^0.5.2",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"pg": "^8.7.1",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"sequelize": "^6.12.2",
"tedious": "^14.0.0",
"uuid": "^8.3.2"
}
}
The code I use to init my db is like this:
function dbInit(app){
const Sequelize = require('sequelize');
const keys = require('../config/keys');
const sqlCon = new Sequelize(keys.dbName,keys.dbUser, keys.dbPassword,
{dialect:'postgresql',
host:keys.dbHost,
pool:20,
logging:false
});
app.locals.connection = sqlCon;
//wire up model definitions
const User = require('../models/User')(sqlCon,sequelize);
const PasswordResetRequest = require('../models/PasswordResetRequest')(sqlCon,sequelize);
const CertType =require('../models/CertType')(sqlCon,sequelize);
const Role =require('../models/Role')(sqlCon,sequelize);
app.locals.User = User;
app.locals.PasswordResetRequest = PasswordResetRequest;
app.locals.CertType = CertType;
app.locals.Role = Role;
//setup relationships between tables
require('../models/relationships')(app);
sqlCon.sync().then(()=>{
return sqlCon.authenticate()
})
.catch((err)=>{
console.log('Successfully NOT connected to DB!');
console.log(err);
});
return sqlCon;
}
Can anyone shed any light on why this error happens? Thanks! I already downgraded sequelize from version 7-aplha2.
I have the below node js code that it works perfectly fine locally but when I deploy it to heroku I get an error says "Error: Cannot find module 'express'
internal/modules/cjs/loader.js:968 throw error"
const port = process.env.PORT || 5000;
const express = require('express');
require('dotenv').config();
const app = express();
app.set('view-engine','ejs');
app.use(express.urlencoded({extended:false}));
app.get('/',(req,res) => {
res.render('index.ejs');
});
app.listen(port, ()=>{console.log(`Listening on http://localhost:${port}`)});
package.json
{
"name": "mtNodeApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"devStart": "nodemon index.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"ejs": "^3.1.3",
"express": "^4.17.1",
"mongoose": "^5.10.0",
"nodemon": "^2.0.4",
"request": "^2.88.2"
}
}
Any thoughts, I am not sure what I am missing?!
Thank you
Express must be on dependencies instead of devDependecies:
{
...
"dependencies" {
"express": "^4.17.1",
...
}
"devDependecies": {
...
}
Also, probably most of them must be in dependencies, in order for the server to know what must be installed. Basically, it's ignore the installation of your modules since those are for development and not production.
Edit: If you wanna know more about it, you can read this great answer.
Stackoverflow answer
From an nppm audit i am getting 3 High errors with Q.
npm audit fix does not resolve them.
They seem to be able to be resolved with a high version than 6 but i have version 6.5.2. installed and still getting the errors.
Any help on what might be causing this or a workaround would be great!
Error 1: High Denial-of-Service Extended Event Loop Blocking
Package qs
Patched in >= 1.x
Dependency of node-modules
Path node-modules > request > qs
Error 2: High Denial-of-Service Memory Exhaustion
Package qs
Patched in >= 1.x
Dependency of node-modules
Path node-modules > request > qs
Error 3: High Prototype Pollution Protection Bypass
Package qs
Patched in >=6.0.4 <6.1.0 || >=6.1.2 <6.2.0 || >=6.2.3 <6.3.0 ||
>=6.3.2
Dependency of node-modules
Path node-modules > request > qs
Adding package.json
{
"name": "jpkmdfpackage",
"engines": {
"node": ">=0.12"
},
"repository": {
"type": "git",
"url": "https://git.heroku.com/magic-order-application.git"
},
"version": "1.0.0",
"main": "server.js",
"dependencies": {
"#hapi/cryptiles": "^5.0.0",
"body-parser": "^1.19.0",
"connect-ensure-login": "^0.1.1",
"cryptiles": "^4.1.2",
"ejs": "^3.0.1",
"express": "^4.17.1",
"express-handlebars": "^3.1.0",
"express-session": "^1.17.0",
"git": "^0.1.5",
"mongodb": "^3.5.5",
"mongoose": "^5.9.6",
"morgan": "^1.9.1",
"node-gyp": "^6.1.0",
"node-modules": "^1.0.1",
"node-pre-gyp": "^0.14.0",
"nodegit": "^0.26.5",
"npm-lifecycle": "^3.1.5",
"passport": "^0.4.1",
"passport-local": "^1.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"description": "MagicOrder Application"
}
I never used a module outside a boilerplate created by for example create-react-app or angular-cli, now i am trying to mimic modularity without using them, and i get an error: cannot use import outside a module
this is my package.json file:
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0"
}
}
I am using a live-server to create a server for my project, I am failing to do that:
App.js:
const x = 10;
export default x;
index.js:
import x from './App' // can not use import outside a module
The question is what i missing here, what do i really need to create a module??