Error message: "Unexpected syntax found in my Express code using Node.js"

Currently, I am following a tutorial video and trying to implement the code provided. This is the code snippet at the beginning of my routes/index.js file:

var todo = require('../todo'); //line 1
//line 2
//new session //line 3
exports.newSession = function (req, res) { //line 4
  res.render('sessions/new', { //**line 5**
    locals: {
      redir: req.query.redir
    }
  });
};

After executing my app and activating the routes.newSession handler, I encountered an error:

500 SyntaxError: Unexpected identifier
at Object.Function (unknown source)
at Object.compile (/home/admin73464/todo/node_modules/jade/lib/jade.js:161:8)
at Function.compile (/home/admin73464/todo/node_modules/express/lib/view.js:65:33)
at ServerResponse._render (/home/admin73464/todo/node_modules/express/lib/view.js:414:18)
at ServerResponse.render (/home/admin73464/todo/node_modules/express/lib/view.js:315:17)
at /home/admin73464/todo/routes/index.js:5:6
at callbacks (/home/admin73464/todo/node_modules/express/lib/router/index.js:272:11)
at param (/home/admin73464/todo/node_modules/express/lib/router/index.js:246:11)
at pass (/home/admin73464/todo/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/home/admin73464/todo/node_modules/express/lib/router/index.js:280:4)

I have reviewed my index.js file for syntax errors but couldn't find any. Should I be troubleshooting elsewhere?

Your input is appreciated!

In response to some suggestions, here is the content of my views/sessions/new.jade file:

h1 Login
form(action='/sessions', method='POST')
  input(type='hidden', name='redir', value=redir)
  p
    label(for='login') Login:
    input(type='text' name='login', id='login')
  p
    label(for='password') Password:
    input(type='password' name='password', id='password')
  p
    input(type='submit')

I have made sure to replicate the instructions accurately.

Furthermore, I am utilizing a layout.jade file as well. Here is its content:

!!!
html
  head
    title Our ToDo App
    link(rel='stylesheet', href='/stylesheets/style.css')
  body!= body

Despite making adjustments in response to feedback, the error persists. Your ongoing support is greatly valued.

As per a suggestion, I have shared my app's folder and files at

The directory structure conforms to Express's default setup, which should aid in comprehension.

Answer №1

Make sure to include commas between the type and name attributes in your new.jade file. Take a look at the following lines:

input(type='text', name='login', id='login')
input(type='password', name='password', id='password')

Remember, when using Jade, it's important to separate HTML attributes with commas.

Answer №2

Could there be an issue with the sessions/login.jade template?

Answer №3

Could you please modify the content of index.js as shown below and let me know if it resolves the issue:

exports.createSession = function (request, response) {
  var redirectUrl = (request.query && request.query.redirect) || '';
  response.render('sessions/create', { redirectUrl: redirectUrl });
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display a secure image retrieved from an API on a Next.js client using an <img> element

Currently, I am facing a challenge in displaying an image that is protected within my Node.js backend assets folder. The backend setup includes a middleware that verifies whether the user is authenticated and has the necessary permissions to view the file ...

Cassandra encountered a TypeError stating that the "value" argument is exceeding the bounds

I keep encountering the error message below. Any thoughts on what might be causing it? TypeError: "value" argument is out of bounds at checkInt (buffer.js:1041:11) at Buffer.writeInt32BE (buffer.js:1244:5) at Encoder.encodeInt (/ ...

Utilizing Promises in the apply function

I am currently working on a project in Node.js that utilizes bluebird for promise handling, as well as ES6 native promises. In both projects, I have a chain where I make a database query structured like this: some_function(/*...*/) .then(function () ...

Could Warmup Requests in NodeJS Lead to Data Corruption?

I currently have a running node server in App Engine standard with a custom domain and everything is functioning smoothly. However, whenever I deploy a new version, there is a noticeable increase in latency as the old instances are halted and new ones are ...

I encountered an issue stating, "The function `req.redirect` is not recognized."

Recently starting out with node development. Encountering the error below: TypeError: req.redirect is not a function at Post.create (/var/www/html/node_blog/index.js:40:7) at /var/www/html/node_blog/node_modules/mongoose/lib/utils.js:276:16 a ...

When a process crashes, PM2 automatically launches a new daemon but fails to restart the processes

My application "prod" does not restore on SIGINT, resulting in PM2 crashing all other applications and restarting the daemon. If I manually kill other applications, they function properly by automatically restarting. The logs show: (process:3626): GLib- ...

New and Improved: Node.js Integration for Handling POST Requests with Rally's Latest API Authorization Version 2.0

After setting up a Node.js server to handle Rally POST requests, everything was working perfectly until I made the switch to the new Rally v2.0 API. The updated authorization model has left me scratching my head on what changes I need to make to my serve ...

Tips on integrating Socket.io with Express?

I've written the Express code in my server JS file: app.post('/confirm', function (req, res) { // Currently struggling to send a socket using emit() }); Here is the Socket.io code I have: io.on('connection', function (client) ...

Executing a cURL request using Node.js

Looking for assistance in converting the request below: curl -F <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a777f7e737b275a73777b7d7f34706a7d">[email protected]</a> <url> to an axios request if possible. ...

Having difficulty kicking off a fresh React project on Windows

I've encountered an issue while setting up my React application on Windows OS. After running npm start, the application fails to load on localhost:3000, showing the error message Cannot GET /. Below is the project structure: - webpack.config.js - p ...

Encountering a 404 Error while using my Next.js 13 API Route

I recently forked a project and attempted to set up an API Endpoint for my CRUD operations with a database. However, I encountered difficulties in accessing my endpoint. Even with a test on a dummy API https://jsonplaceholder.typicode.com/todos, I still re ...

Encountering a TypeError when trying to start the nextjs server

Every time I run my next server with npm run dev, I keep encountering the same error. After testing it on a fully functional project, I am convinced that the issue is not related to the code. I suspect that the problem may be caused by running: npm insta ...

Tools needed for Angular project development

Currently, I am engaged in a project using AngularJS on a Windows 7 computer. My desire is to be able to seamlessly transition between working at the office and working from home or any other location. If I have everything installed in a folder named C:/C ...

Angular Universal involves making two HTTP calls

When using Angular Universal, I noticed that Http calls are being made twice on the initial load. I attempted to use transferState and implemented a caching mechanism in my project, but unfortunately, it did not resolve the issue. if (isPlatf ...

pnpm may not be able to resolve dependencies

When I have my package.json file and install all dependencies with npm i, everything works fine. However, when I use pnpm i, I encounter an exception: TypeError: Cannot read property 'uid' of undefined. I don't actually use this library, so ...

Dockerhub build process encountering errors with npm install bcrypt causing automated build to fail

I have a Dockerfile setup as follows: FROM ubuntu:14.04 MAINTAINER John Doe <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d28202c24210d20342c3d3d632e2220">[email protected]</a>> ENV NODE_ENV production ...

Allow Nest.js server to receive binary files in the request body

Is there a way to retrieve the uploaded binary file data from the browser? While the Nest.js server application functions correctly with Postman, it throws a 400 error when the request is sent from the Google Chrome/Angular application. Any ideas on how ...

Deploying React.js: Should you release the client and server separately or as a cohesive unit?

I currently have a react.js website with a backend in Node/express that is being hosted on Azure. The project is currently set up as monolithic, meaning every time I make a change to either the front-end or back-end, everything has to be redeployed in pr ...

Having a problem with Gulp not producing the minified CSS file

Despite following a straightforward tutorial and executing all the necessary commands, I am still encountering an issue with Gulp not generating the uglified CSS file in the designated "destination" folder. Here is the code snippet: var gulp = require("gu ...

What is the best way to retrieve the document DOM object within an EJS template?

I am attempting to display a list of participants when the user clicks on the button. However, every time I try, I encounter an error stating "document is not defined". (Please refrain from suggesting the use of jQuery!). <% var btn = document.getEle ...