import
I am building an app in HTTPS-NODE, and when I try to import something from my js file, it cannot find it, event if I put "import path from '/node_modules/path' it just doesn't find anything... Can someone help me?
24 Replies
Project ID:
N/A
N/A
If it is just a regular json file, you can just
import
and then return it.⚠️ experimental feature
Does not works
could we see a repo?
Can I just write it down over here?
That's my server.mjs (main file)
import express from 'express';
var app = express();
import path, { join } from 'path';
import { createServer } from 'http';
import { fileURLToPath } from 'url';
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
var server = createServer(app);
server.listen(process.env.PORT);
app.use(express.static(join(dirname, 'public')));
app.use('/src',express.static(join(dirname, 'public/src')));
app.use('/node_modules',express.static(join(dirname, 'node_modules')));
app.use('/html',express.static(join(dirname, 'public/html')));
app.get('/', function (req, res) {
res.sendFile(dirname + '/index.html');
});
And this is how I'm trying to import on my teste.mjs (file for the page):
import path from '/node_modules/path';
import { fileURLToPath } from '/node_modules/url';
That's the structure
id prefer a repo
The repo, is it the repository on github?
I'm new at git therms
yes
i dont know if repo is a term, im just lazy
GitHub
GitHub - kevinuzan/http-nodejs
Contribute to kevinuzan/http-nodejs development by creating an account on GitHub.
There u go
okay now can i see a screenshot of the deploy log error
I just don't know how to import a module to my teste.mjs...
so why do you need to access the node_modules folder in the frontend?
I mean, I need to import the module on a mjs file
That one that you are seeing on the html, was just a test
thats not quite how that works
Here is what I want it to do:
When I click on a button, it loads a new html, changing the screen
But to do it, shouldn't I kind of tell it where is the file and all?
no you shouldn't need to access the node_modules folder in the frontend, i recommend you look for some tutorials on this topic and work through them locally
So if I need to use a module, like for example, postgreSQL module, on my webapp, shouldn't I import it on my mjs file?
i guess im just struggling to explain this, normally you would use a bundler like vite
And that's what makes the "Connection" between the modules that I installed on my app, and my pages?
vite will bundle your code and any required module into the same file