I'm new to node js
so please forgive me if I say something wrong. I want to create a project and test it locally.
So I've created a node js
project with (in same directory):
app.js
--> where I create thelocalhost:8080
index.html
--> myhtml
main page- within this, I've a call to
test.js
script
- within this, I've a call to
Those are my files:
app.js
const express = require('express');
const app = express();
port = 8080;
app.use(express.static(__dirname));
app.listen(port, function(){
console.log('Server in ' + port);
});
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="module" src="test.js"> </script>
</body>
</html>
test.js
import axios from 'axios'
// Non important stuff
But when I try to import npm
libraries to test.js
script, as shown right above, I get this error
Uncaught TypeError: Failed to resolve module specifier "express".
Relative references must start with either "/", "./", or "../".
And if I try to use require
, it shows me this error:
// test.js:1 ==> const axios = require('axios')
Uncaught ReferenceError: require is not defined
at test.js:1
(anonymous) @ test.js:1
EDIT CHANGED MY DIRECTORY My folder is this:
I've changed my directory but still remains the same problem
Previous question: Why is showing me that error? What am I doing wrong?