“Ekspres Folder Publik” Kode Jawaban

Bagaimana Express Melayani Folder Publik

// projectDirectory/src/index.js
const path = require('path')
const publicDirectoryPath = path.join(__dirname, '../public')
app.use(express.static(publicDirectoryPath))

// projectDirectory/public -> create index.html
// localhost:3000/index.html -> Here you go..

Depressed Dunlin

File statis server Node Express

var express = require('express');
var app = express();
var path = require('path');

//app.use(express.static(__dirname)); // Current directory is root
app.use(express.static(path.join(__dirname, 'public'))); //  "public" off of current is root

app.listen(80);
console.log('Listening on port 80');
JDog

Folder Statis Express

// dependencies
const path = require('path');

// set static folder
app.set(express.static(path.join(__dirname, 'public')));
Mehedi Islam Ripon

Ekspres Folder Publik

app.use(express.static('public'))
app.use(express.static('files'))
Testy Tamarin

Gunakan statis dengan ekspres

app.use(express.static('directoryName'))
#store the files in the directory as if you were making a website without express
Encouraging Elk

Jawaban yang mirip dengan “Ekspres Folder Publik”

Pertanyaan yang mirip dengan “Ekspres Folder Publik”

Lebih banyak jawaban terkait untuk “Ekspres Folder Publik” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya