1

I don't understand what is wrong. Node v.16.4.2, NPM v7.18.1

const mongoose = require("mongoose");
// const dotenv = require('dotenv')
require('dotenv').config({path:'variables.env'});

mongoose.connect(process.env.MONGODB_URL, { useNewUrlParser: true}, err => {
    if (err){
        console.log(err);
    } else {
        console.log("Connected to database successfully");

    }
})

/* mongoose.js */
const db = mongoose.connection;

db.on('error', console.error.bind(console, 'connection error'));
db.once('open', ()=>{
  console.log('DB connected');
});

const express = require('express');
const app = express();
app.get('/', (req, res) => {
  Cat.find({}, (err, healings) => {
    if(err) return res.json(err);
    res.json(healings);
  });
});
app.listen(3000, () => {
  console.log('Connect 3000');
});

const userSchema = mongoose.Schema({
    emotion: Number,
    image: String,
    placeName: String,
    grade: Number,
    id: mongoose.Schema.Types.ObjectId,
});
  ​
const Healing = mongoose.model("user", userSchema); // 스키마 등록
var test = new Healing({ emotion: 1111, image: 'test', placeName:'where', grade:5 });
test.save();

//  const Cat = mongoose.model('Kitty', CatSchema);

the error is

/Users/Downloads/test2/mongoose.js:41

SyntaxError: Invalid or unexpected token at Object.compileFunction (node:vm:352:18) at wrapSafe (node:internal/modules/cjs/loader:1025:15) at Module._compile (node:internal/modules/cjs/loader:1059:27) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:816:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) at node:internal/main/run_main_module:17:47

1
  • Are you using an encoding other than UTF-8? Try ensuring your source code files are UTF-8 encoded and try again. Commented Jul 13, 2021 at 1:49

2 Answers 2

1

I think it's an encoding issue.

Please see, for example: How to fix `SyntaxError: Invalid or unexpected token` when trying to run Node.js app

Try saving your source code file with UTF-8 encoding.

Sign up to request clarification or add additional context in comments.

Comments

1

The error calls out line 41, which appears to be the blank line immediately prior to

const Healing = ...

When I copy/paste that line into Vim, it shows <200b>, which suggests that line contains a zero-width space (properly encoded in UTF-8).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.