When I run the following code:
var app = require('express')();
var http = require('http').Server(app);
app.get('/', function(req, res){
res.send('<h1>Hello world</h1>');
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
I get the following error:
/var/www/html/test.me/public_html/giftcard/index.js:1
rts, require, module, __filename, __dirname) { var app = require('express')();
^
TypeError: object is not a function
at Object.<anonymous> (/var/www/html/test.me/public_html/giftcard/index.js:1:91)
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:902:3
What does this error mean? Is the path to express incorrect? I have one directory with packages.json
, index.js
(the file above), and node_modules
, and I have express installed. Where is the error coming from?
Copyright Notice:Content Author:「mitmath514」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53998493/node-js-express-typeerror-object-is-not-a-function