简体   繁体   中英

Coffeescript + Express.js : cannot call method 'sliced' of undefined

I'm making my first app in express.js and coffeescript. The code is at: https://github.com/findjashua/contactlist

When I try to run it, I get the following error:

/Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/helpers.js:216
  codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end
                      ^
TypeError: Cannot call method 'slice' of undefined
  at Object.exports.prettyErrorMessage (/Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/helpers.js:216:27)
  at compileScript (/Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:199:25)
  at /Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:143:18
  at fs.js:266:14
  at Object.oncomplete (fs.js:107:15)

I'm assuming it's something to do with contacts.coffee, but can't think of anything. Any ideas?

You never close the parens for new ContactModel( .

  exports.addContact = (req, res) ->
contact = new ContactModel(
    name: req.body.name
    phone: req.body.phone
contact.save((err) ->
    if not err
        console.log('created')
        res.send(contact)
    else
        res.send(error)
)

My tip: forget all these parens. Part of the nice thing about coffeescript is you can use indentation and not have big chains of floating closing delimiters like the close parens in your source. Just do:

someFunction (arg1, arg2) ->
  body of nested function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM