Is there a way to hide a json file’s extension (example: blabla.glitch.me/…/…/pack.json) in url but keeping it as a .json file inside?
You can configure the express.static()
function with a list of default file extensions that it will use when searching for static files
app.use(express.static('/public', {
extensions: ['html', 'htm', 'json']
}));
EDIT: It is public
not /public
. My mistake
Where do I use that? sorry i’m new on this lul
Do you have an express server running in your project?
If you have a file named server.js
that is your express server. Find the app.use(express.static('public'));
line.
This function serve the static files of the public
folder.
Look here. Line 8-10 of server.js. Read the description
I’m using a webpage, not express ._.
I made a research and I couldn’t config the lws
server of a hello-webpage to do this.
I think your best option is to move to a hello-express app.
You can use the public folder as your root directory of the webpage
And change that line I showed you earlier.
An express app is a more configurable server than a hello-webpage
Maybe somebody else know more than me and can solve it. But I think it is easier to make an express app
Well, I tried it but when I went to the file’s link, It said “Cannot GET …”
What can I do?
Can you show me your code? Or give me your project name so I can see where is the error
EDIT: Sorry: It was my error. I wrote /public
instead public
This is the right code
app.use(express.static('public', {
extensions: ['html', 'htm', 'json']
}));
I added you on Discord, can you accept it please?
You have to name the file like this public/pack.json
This will create a file pack.json
inside your public directory.
Add me again, I didn’t know it was you haha