How do N identify the path from the root of the request?

Asked

Viewed 338 times

2

It’s like this:

<link rel="stylesheet" href="http://localhost/node/softmon/css/style.css" type="css">

If I put it like that:

<link rel="stylesheet" href="/css/style.css" type="css">

doesn’t work.

I use it to view the page ***http://localhost:3000***

app js.

var app = require('express')(),
http = require('http').Server(app),
io = require('socket.io')(http),
dbasy = require('./node_modules/dbasy/dbasy.js'),
$ = require('cheerio'),
jsdom = require("jsdom");

app.get('/', function(req, res) {
    res.sendFile(__dirname + '/index.htm');
});
io.on('connection', function(socket) {
    socket.on('operacoes', function(data) {
        console.log()
    }); 
    socket.on('disconnect', function () {
        console.log('Desconetado.');
    });
});
http.listen(1589, function(){
    console.log('Servidor iniciado.');
});

How to make Node identify the path from the root of the request ?

  • no view defined, I load the page directly from the app.get('/', Function(req, res) { res.sendFile(_dirname + '/index.htm'); });

1 answer

1


You have to define how static files are used. Join this in index.js:

app.use(express.static(__dirname + '/node/softmon/'));

assuming the folder where you have the index.js has a subfolder /node/.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.