0

I am learning how to use custom middlewares properly by following this example here

I placed the datetime.js file in my server/middleware folder and try to use it in my server.js (according to the documentation on Middlware here):

var datetime = require('datetime');
app.middleware('initial:before', datetime());

However, when I try to start the app by 'slc run', I got complaint that

Error: Cannot find module 'datetime'

So I suspect if the server can even detect the middleware 'datetime'. What is the right way of using custom middleware in loopback?

thanks

TonyW
  • 18,375
  • 42
  • 110
  • 183

1 Answers1

0

You need to require datetime using a relative path. The server will not automatically figure out dependency paths for you.

 var datetime = require('./middleware/datetime');
superkhau
  • 2,781
  • 18
  • 9