Skip to content

"Invalid or unexpected token" at single quotation mark #2204

Closed

Description

@KitchenLedger

I have a problem getting this to work file name : index.js

const express = require(‘express’);
const bodyParser = require(‘body-parser’);
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(3000, () => console.log(‘Webhook server is listening, port 3000’));

but when I type node index.js, this is what I get....

Dereks-iMac:msgbot derekvann$ node index.js
/Users/derekvann/Desktop/msgbot/index.js:1
const express = require(‘express’);
                        ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Activity

  1. transferred this issue fromnodejs/nodeon Sep 26, 2019
  2. ORESoftware commented on Sep 27, 2019

    @ORESoftware

    you are likely using an older node.js version, whereby it doesn't recognize the const keyword.

    when you type node -v in the terminal, what do you get?

    to install a newer version of node.js on a non-windows machine, I recommend NVM.

  3. ORESoftware commented on Sep 27, 2019

    @ORESoftware

    on this note @bnoordhuis it would be kinda neat to display the node.js version in all node.js stacktraces, at the end. think about how much time this would save users debugging etc, and on online messsage boards.

  4. KitchenLedger commented on Sep 27, 2019

    @KitchenLedger
    Author

    I have Version 10.16.3
    is that too old?

  5. bruce-one commented on Sep 29, 2019

    @bruce-one

    That version should support const.

    It is possible that the quotes you have are not ' but instead are another character.

    Could you try replacing the quotes (eg rewriting them or replacing with double quotes) to see whether that resolves the issue?

    The quotes on all the lines look they are ’ rather than '. This is a common issue if copying from sites like Medium which can replace quotes with the "nicer looking" alternatives.

  6. tniessen commented on Oct 13, 2019

    @tniessen
    Member

    @bruce-one is right, you are using some fancy unicode quote characters instead of "normal" single-quotes. If you replace them, it should work.

  7. changed the title [-]Help with Node Please[/-] [+]"Invalid or unexpected token" at single quotation mark[/+] on Oct 13, 2019
  8. han-so1omon commented on Jan 11, 2020

    @han-so1omon

    I am having this same error, but it only occurs when splitting a string into multiple lines. When the string is in one line the error goes away.

    Error example:

    'String 1
    is this string
    ';
    

    Correct example:

    'String 2 is this string';
    

    This is using nodejs v12.13.1

  9. tniessen commented on Jan 11, 2020

    @tniessen
    Member

    @han-so1omon That's intentional. If you want line feeds, use the \n escape sequence:

    'String 1\nis this string\n';
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions