S
S
SpideR-KOSS2018-05-10 13:21:15
JavaScript
SpideR-KOSS, 2018-05-10 13:21:15

How to execute html file in node js?

Good afternoon!
There is an HTML file with markup and javascript functions inside.
Accordingly, when you run the file in the browser, everything works, but on the client.
I need this file to run and work the same way, but only on the Node JS server.
How to do it easier?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Okhotnikov, 2018-05-15
@SpideR-KOSS

Here is an example of a Node server that returns an index.html
file. Create an app.js file and put this code in it. in the app folder, create a public folder and put all the html there.
Then run app -node app.js and on localhost:3000 you will be able to see your site

const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');

const app = express();

// Body Parser Middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

var staticSiteOptions = {
  portnum: 3000, 
  maxAge: 1000 * 60 * 15 
};

 app.use(express.static(
   path.join(__dirname, 'public'),
   staticSiteOptions
 )).listen(staticSiteOptions.portnum);

V
Vladimir Skibin, 2018-05-10
@megafax

phantomjs.org - Your solution in this case

J
Jumandjilos, 2018-05-10
@Jumandjilos

Well, create a server, and, for example, when you go to localhost, give the html file. In short, study yourself a little node, and you will understand everything, these are the basics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question