-2

I'm trying to execute a simple express script in javascript. Everytime I try I receive an error of "require is not defined". code snippets below... Thanks!

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

app.get('/', (req, res) => {
    res.send('An alligator approaches!');
});

app.listen(3000, () => console.log('Gator app listening on port 3000!'));

and the index.html file looks like such...

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="basic.js"></script>
</head>
<body>

</body>
</html>
Rogue33
  • 43
  • 1
  • 6

1 Answers1

1

Hi as you may know NodeJS is a server side language so it cannot be understand by your browser.

Actually you have created an express server using NodeJS, so if you want to execute your server just run "node basic.js" in your terminal.

nathanagez
  • 36
  • 1
  • 6
  • I wasn't aware I needed to execute express via the command line. I was trying to execute via browser. Thanks for the quick response! – Rogue33 May 11 '18 at 21:18