const express = require('express')
const User = require('../models/User')
const auth = require('../middleware/auth')
const router = express.Router()
router.post('/users', async (req, res) => {
// Create a new user
try {
const user = new User(req.body)
const status = 1
await user.save()
const token = await user.generateAuthToken()
res.status(201).send({status, user, token })
} catch (error) {
res.status(400).send(error)
}
})
router.post('/users/login', async(req, res) => {
//Login a registered user
try {
const { email, password } = req.body
const user = await User.findByCredentials(email, password)
const status = 1
if (!user) {
return res.status(401).send({error: 'Login failed! Check authentication credentials'})
}
const token = await user.generateAuthToken()
res.send({ status,user,token })
} catch (error) {
res.status(400).send(error)
}
})
router.get('/users/me', auth, async(req, res) => {
// View logged in user profile
res.send(req.user)
})
router.post('/users/me/logout', auth, async (req, res) => {
// Log user out of the application
try {
req.user.tokens = req.user.tokens.filter((token) => {
return token.token != req.token
})
await req.user.save()
res.send()
} catch (error) {
res.status(500).send(error)
}
})
router.post('/users/me/logoutall', auth, async(req, res) => {
// Log user out of all devices
try {
req.user.tokens.splice(0, req.user.tokens.length)
await req.user.save()
res.send()
} catch (error) {
res.status(500).send(error)
}
})
router.patch('/users/places/:id', auth, async (req, res) => {
const updates = Object.keys(req.body)
const allowedUpdates = ['places']
const isValidOperation = updates.every((update) => allowedUpdates.includes(update))
if (!isValidOperation) {
return res.status(400).send({ error: 'Invalid updates!' })
}
try {
const task = await Task.findOne({ _id: req.params.id})
if (!task) {
return res.status(404).send()
}
else{
updates.forEach((update) => {
task[update] = update === 'places'
? task[update].map(places=>places.place === req.body[update].place ? req.body[update] : places)
: req.body[update]
})
updates.forEach((update) => {
task[update] = update === 'places'
? task[update].map(places=>places.latitude === req.body[update].latitude ? req.body[update] : places)
: req.body[update]
})
updates.forEach((update) => {
task[update] = update === 'places'
? task[update].map(places=>places.longitude === req.body[update].longitude ? req.body[update] : places)
: req.body[update]
})
}
await task.save()
res.send(task)
} catch (e) {
res.status(400).send(e)
})
module.exports = router
It is showing an error at line no 102
Unexpected end of input as error and I am not able to understand the error as I am new to the code in nodejs.
below given is the log of the yarn run v1.22.4
4:23:43 PM web.1 | $ env-cmd -f ./.env node src/app.js
4:23:44 PM web.1 | H:\Minor\Backend\src\ro
4:23:44 PM web.1 | uters\user.js:106
4:23:44 PM web.1 | module.exports = router
4:23:44 PM web.1 | SyntaxError: Unexpected end of input
4:23:44 PM web.1 | at wrapSafe (internal/modules/cjs/loader.js:1072:16)
4:23:44 PM web.1 | at Module._compile (internal/modules/cjs/loader.js:1122:27)
4:23:44 PM web.1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
4:23:44 PM web.1 | at Module.load (internal/modules/cjs/loader.js:1002:32)
4:23:44 PM web.1 | at Function.Module._load (internal/modules/cjs/loader.js:901:14)
4:23:44 PM web.1 | at Module.require (internal/modules/cjs/loader
4:23:44 PM web.1 | .js:1044:19)
4:23:44 PM web.1 | at require (internal/modules/cjs/helpers.js:77:18)
4:23:44 PM web.1 | at Object.<anonymous> (H:\Minor\Backend\src\app.js:3:20)
4:23:44 PM web.1 | at Module._compile (internal/modules/cjs/loader.js:1158:30)
4:23:44 PM web.1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
4:23:44 PM web.1 | error Command failed with exit code 1.
4:23:44 PM web.1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[DONE] Killing all processes with signal SIGINT
4:23:44 PM web.1 Exited with exit code nullterminal showing the error
приведенное выше является журналом кода, работающего в терминале, и ошибка является неожиданным токеном ')' Пожалуйста, помогите мне решить эту ошибку, поскольку я новичок в node js, поэтому я не не знаю много об этом, и в Google также я не могу найти никакого решения ................................. .................................................. .................................................. .................................................. .................................................. .................................................. .................................................. .................................................. .................................................. .................................. Пожалуйста, просмотрите мой код один раз и помогите мне в его разрешении.