I begin to use Nodejs to create web servers, and for this, I use express module. Then, I intalled it with command : "sudo npm install -g express". But after lanched the program, this error occured :
"ReferenceError: express is not defined at Object. (/home/louis/Documents/Programming/Web/Nodejs/Test/server.js:1:85) at Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Function.Module.runMain (module.js:684:10) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3 "
I decided to install it localy but in vain...
Here is the code I use :
let express = require(express);
let app = express();
console.log("Hello world !");
app.listen(80);
Thanks
Express needs to be in quotes
let express = require('express')
Off-Topic:
You probably don't want that variable to be modified in the future, so you probably want to force it to stay that way. Most time you want required variables to be constant
which is a common practice:
const express = require('express')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With