Node.js: cannot call method 'use' of undefined

I'm trying to learn node.js and I'm getting this error.

app.use(morgan('dev')); //log request to console
TypeError: Cannot call method 'use' of undefined
at Object.<anonymous> (/root/authproject/server.js:21:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

What could be causing it?

You're going to need some code like this to setup express:

var express = require('express');
var app = express();

And you'll need to import morgan similarly. I'm presume you're copying the code from somewhere - perhaps it's not a complete example?