“Dossier public Expresser” Réponses codées

Comment servir le dossier public express

// 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

Node Express Server Fichiers statiques

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

Dossier statique Express

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

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

Dossier public Expresser

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

Utilisez statique avec les expres

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

Réponses similaires à “Dossier public Expresser”

Questions similaires à “Dossier public Expresser”

Plus de réponses similaires à “Dossier public Expresser” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code