Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(node:6868) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` is deprecated

First time I have come across such an error so forgive me if I fail to note any important factors here. The full error I get upon running my code is:

(node:10812) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` is deprecated. Please use `node --inspect-brk` instead.

As shown here:

enter image description here

It also highlights this line of code:

return new Script(code, options);

As shown here:

enter image description here

This is the version of node.js I'm running as shown by nvm.

C:\Users\jonat>nvm install latest
Version 8.4.0 is already installed.

I ran the VS installer yesterday so it is up to date.

These are the modules I'm using:

const   express                 = require("express"),
        mongoose                = require("mongoose"),
        passport                = require("passport"),
        bodyParser              = require("body-parser"),
        LocalStrategy           = require("passport-local"),
        passportLocalMongoose   = require("passport-local-mongoose"),
        math                    = require("mathjs");

They have been installed via npm and I have recently run .npm update here they are shown in heir file directory:

enter image description here

Here various setting are changed and variables that will be used further on are set:

const app = express();

const   uri = 'mongodb://localhost/MathsWebsite',
        options = { useMongoClient: true };

mongoose.Promise = global.Promise;
mongoose.set('debug', true);

app.set('view engine','ejs');
app.use(bodyParser.urlencoded({extended:true}));
app.use(require("express-session")({
    secret:"fanatical beaver",
    resave: false,
    saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());

passport.use(new LocalStrategy(user.authenticate()));
passport.serializeUser(user.serializeUser());
passport.deserializeUser(user.deserializeUser());

Notably I can run the code using:

C:\Users\jonat\Documents\GitHub\MathsSite\MathsWebsite>node server.js --no-deprecation

Which then results in the linked error (https://hastebin.com/lajotaqifo.rb) as shown:

enter image description here

The seed.js function being at the bottom of the code as shown:

mongoose.connect(uri, options)
    .then(() => seedDB)
    .then(() => app.listen(process.env.PORT, process.env.IP, function () {
        console.log("Server started");
    }))
    .catch(error => console.log("error"));

Imported as shown:

const   seedDB                  = require("./seed");

Exported as shown:

async function seedDB() {...}
module.exports = seedDB;

And is located in the file directory as shown:

enter image description here

This error I beleive is not associated with the deprecated issue although I thought it best I mention it. Although I beleive I can bypass this issue as I have shown I don't think this is acceptable in the long term, if anyone can provide a solution to this issue or even just point me in the right direction it would be greatly appreciated.

(Also just in case it is necessary here are the links to the full code from both server.js (https://hastebin.com/ibuweyaxes.js) and seed.js (https://hastebin.com/ibuweyaxes.js) in hastebin) In addition would note due to my lacking knowledge on the matter I may well have either included useless things or failed to include useful things.

like image 547
Jonathan Woollett-light Avatar asked Nov 08 '22 17:11

Jonathan Woollett-light


1 Answers

The issue is with the Seed.js file at line 343 as the error message correctly points out, you cannot use await outside of an async function. While SeedDB might be an async function the await code is actually inside the then catch statement, the then must be declared as an async function in order to not error.

The original code snipped from your pastebin looks like this:

}).then(() => {

So simply add async before the arrow function in then like I have done below.

}).then(async () => {

And here's it in the full Promise:

Promise((resolve, reject) => {
        examboardData.forEach(function (examSeed) {
            examBoard.create(examSeed, function (err, exam) {
                console.log("Creating new examboard");
                if (err) {
                    console.log("Could not create new examboard\n" + err);
                }
                else {
                    console.log("Created examboard");
                    exams.push(exam);
                }
            });
        });
        questionData.forEach(function (questionSeed) {
            question.create(questionSeed, function (err, question) {
                if (err) {
                    console.log("Could not create new question\n" + err);
                }
                else {
                    console.log("Created question");
                    questions.push(question);
                }
            });
        });
    }).then(async () => {
        var topicIncrementor = 0;
        for (let question of questions) {
            for (var i = 0; i < exams.length; i++) {
                for (var t = 0; t < exams[i].modules.length; t++) {
                    for (var q = 0; q < exams[i].modules[t].topics.length; q++) {
                        exams[i].modules[t].topics[q].questions.push(question);
                        topicIncrementor++;
                    }
                    topicIncrementor = 0;
                }
                    await exams[i].save();
            }
        }
    });
like image 168
Matthew Loveday Avatar answered Nov 14 '22 23:11

Matthew Loveday