A
A
alexandrtym2017-06-20 17:00:41
css
alexandrtym, 2017-06-20 17:00:41

How to include css file in express (node ​​js)?

Hello. I am trying to include app.component.css file. Unfortunately, it doesn't work. Can you advise something?
server.js

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

var index = require('./routes/index');
var tasks = require('./routes/tasks');

var port = 3000;

var app = express();

//View Engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);

// Set Static Folder
app.use(express.static(path.join(__dirname, 'client')));


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

app.use('/', index);
app.use('/api', tasks);

app.listen(port, function(){
    console.log('Server started on port '+port);
});

html file
<header>
   <link rel="stylesheet" type="text/css" href="/app.component.css" />
</header>

In app.component.ts
import {Component} from '@angular/core';


@Component (
    {
        moduleId:module.id,
        selector: 'app',
        templateUrl: 'app.component.html',
        styleUrls:['app.component.css']
       }
)
export class AppComponent { }

General path of the whole folder to css pr/client/app/app.component.css
server.js - pr/server.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
flareair, 2017-06-21
@flareair

The browser looks for CSS in the pr/client folder, and you have it in pr/client/app/. Looks like you need to fix the paths in the HTML file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question