Search code examples
javascriptnode.jsmongodbread-eval-print-loopmanjaro

node REPL gaves me an infinite loop


Here is my code

import mongoose from "mongoose";
const { Schema } = mongoose;
mongoose.set('strictQuery', false); 
mongoose.connect('mongodb://127.0.0.1:27017/moviesdb')
.then(()=> {
    console.log("Connection Open")
})
.catch(err => {
    console.log("error")
    console.log(err)
})

const movieSchema = new Schema({
    title: String,
    year: Number,
    score: Number,
    rating: String,
});

const Movie = mongoose.model('Movie', movieSchema)
const amadeus = new Movie({title: 'Amadeus', year: 1986})

When I tried

node

and

.load index.js

I got infinite loop says

import mongoose from "mongoose";

I followed instructions on Mongoose website but it gaves me that bug. I'm using latest version of Manjaro Linux, and node version is up to date.


Solution

  • This seems to be a bug in node that has recently developed (at least all the complaints I've seen about it are from 2023), but it is present in both the LTS (v18) and the most current version (v19) of node. As a an alternative, using the bash shell (gitbash), or (I've heard) ubuntu, enter:

    node -i -e "$(< index.js)"