0

When using express.static() in the code below I get an error telling me that the function doesn't exist.

This is my code:

var app = require("express");
var consign = require("consign");
var bodyParser = require("body-parser")
var expressValidator = require("express-validator");

var express = app();
express.set('view engine', 'ejs');
express.set('views', './app/views');

express.use(express.static("./app/public"));
express.use(bodyParser.urlencoded({extended: true}));
express.use(expressValidator());

consign()
    .include('app/routes')
    .then('config/db.js')
    .then('app/models')
    .then('app/controllers')
    .into(express);

module.exports = express;
2
  • 1
    please make sure to always post questions in english here on stackoverflow or use pt.stackoverflow.com if you want to post in portuguese Commented May 11, 2020 at 1:57
  • You're assigning the wrong thing to your express variable. It should be const express = require('express') and const app = express();. Then, you can use express.static() and app.use(). Commented May 11, 2020 at 3:34

1 Answer 1

3
var express = require("express"); // !!!
var consign = require("consign");
var bodyParser = require("body-parser")
var expressValidator = require("express-validator");

var app = express(); // !!!
app.set('view engine', 'ejs');
app.set('views', './app/views');

app.use(express.static("./app/public"));
app.use(bodyParser.urlencoded({extended: true}));
app.use(expressValidator());

consign()
    .include('app/routes')
    .then('config/db.js')
    .then('app/models')
    .then('app/controllers')
    .into(app); // !!!

module.exports = express;

Eu falo inglês, desculpe. Eu normalmente daria uma explicação.

English: I speak English, sorry. I would usually give an explanation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.