Home > OS >  Nodemon crashes simple html
Nodemon crashes simple html

Time:09-27

Hi can't get a simple index.html page to work with nodemon.

index.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    hello ya all
  </body>
</html>

The versions are as follows,

^Cshane@XPS:~/peripheralvisionchecker$ npm -v
8.19.2
shane@XPS:~/peripheralvisionchecker$ node -v
v18.9.0
shane@XPS:~/peripheralvisionchecker$ nodemon -v
2.0.20

Trying to run the simple file index.html with nodemon gives,

shane@XPS:~/peripheralvisionchecker$ nodemon index.html 
[nodemon] 2.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: html,json
[nodemon] starting `node index.html`
/home/shane/peripheralvisionchecker/index.html:1
<!DOCTYPE html>
^

SyntaxError: Unexpected token '<'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1048:15)
    at Module._compile (node:internal/modules/cjs/loader:1083:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:18:47

Node.js v18.9.0
[nodemon] app crashed - waiting for file changes before starting...

Why does nodemon keep crashing?

CodePudding user response:

You need server-side or node module, You can't just run html files by nodemon, Nodemon is live javascript runner.

Information about How does server side works & Choose backend framework or module as you like to call, Like:

Express JS, Koa, Fastify, Nest, Ember JS, BackboneJS, Vue JS, Knockout JS, Angular, Meteor, Sails JS and more

You can check documentation for each by just searching "(Express Documentation e.g.)" to get more information about the server side that you want to use, I recommend you to use ExpressJS, As far as projects that i did with expressjs it's amazing.


I would like also to take a look on

Server-side website programming

Express/Node introduction

Introduction to the server side

CodePudding user response:

Then you want to create a quick server that will serve that. It's just an index.js file with a couple of lines that ends with something.listen();. Here's an example

const http = require("http"); 
//create a server object: 
http 
  .createServer(function (req, res) { 
    res.write("<h1>Hello World!</h1>");  
    //write a response to the client 
     
    res.end();  
    //end the response 
  }) 
  .listen(8080);  
//Server runs on localhost:8080 

CodePudding user response:

It looks like you are just editing a static HTML file. Once you save the file just refresh your browser and you should see your changes.

  • Related