Answers for "convert express to static html"

10

Render static html files in 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');
Posted by: Guest on May-11-2020
-2

express static page

const express = require('express')
const path = require('path')

const app = express()
app.use('/public', express.static(path(__dirname) + '/public'))
// the directory '/public' represents whatever direcotory your html file is
// example: if your host naturally looks for a file named 'index.html', then
//   when running this server on that host, it will look in the directory for
//   'index.html' and will automatically display it when someone goes to 
//   (yoursite).com.  It varies from host to host.
//   Otherwise, read the docs for additional options.

// http://expressjs.com/en/4x/api.html#express.static
Posted by: Guest on January-29-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language