Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs : ReferenceError: express is not defined [closed]

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

like image 517
Louis Avatar asked Mar 08 '23 02:03

Louis


1 Answers

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')
like image 110
Get Off My Lawn Avatar answered Mar 09 '23 14:03

Get Off My Lawn