Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected Token ILLEGAL - response.write() error

Tags:

node.js

As sort of an introduction to node.js for a class, I'm using it to program a cgi script that handles a simple login/logout/userID system. I'm having an issue though, as where I try to use the response.write() method to hand the HTML to the client, I'm receiving an Unexpected Token ILLEGAL error on the quotation mark where I am starting my string:

var response = require('HTTP');
login = inputReader('QUERY_STRING');

if (login === "false" || login === "logout") {
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(
  " <!doctype html>
    <head>
      <title>Session Makes</title>
      <meta name='Author' content='Sam Judson'>
      <meta name='Contact' content='[email protected]'>
      <link rel='stylesheet' href='SessionMaker.css'>
    </head>
        <body>
          <h1>The way is shut.</h1>
          <form action='' method='put'>
            <input type='text' name='login'>
            <input type='submit' name='login' value='Login'>
            </form>
        </body>
        </html> "
);
};

The error gets thrown at the quotation mark that starts line 7. I've tried just about everything I can (using single instead of double quotes, nesting quotes, removing the quotes, putting the string inside brackets, etc.), but nothing seems to work. The weird thing is I've seen a number of examples on websites doing the exact same thing I'm trying to do, with no such issue.

like image 898
Dr. Dudley Eigenvalue D.D.S. Avatar asked Jul 18 '26 04:07

Dr. Dudley Eigenvalue D.D.S.


1 Answers

It seems that you have wrong formatting for the string, in javascript you can't continue a string to a new line without either escaping the newline or adding strings over lines.

This will throw an error:

  var str = "Starting string
  trying to continue";

Using escaping

  var str = "Starting string\
  trying to continue";

Using adding

  var str = "Starting string" +
  "trying to continue";
like image 91
DeadAlready Avatar answered Jul 20 '26 19:07

DeadAlready



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!