javascript - Can't find controller in routes file hapijs -
i'm new whole nodejs world , i'm trying create simple app hapi.js myself started around here. anyways, i've got routes file setup way:
var userscontroller = require("./src/controllers/userscontroller.js"); exports.register = function(server, options, next) { server.route([ { method: 'post', path: '/register', handler: userscontroller.register }, ]); next(); }; exports.register.attributes = { name: 'routes', version: '0.0.1' };
and have controller
var hapi = require('hapi'); var usermodel = require('./src/models/user.js'); function userscontroller(){}; userscontroller.prototype = (function(){ return { register: function register(request, reply) { var newuser = user({ name: request.params.name, username: request.params.username, password: request.params.password }); newuser.save(function(err){ if (err) throw err; console.log("you created motherfucking user, bruh"); }) }, } })(); var userscontroller = new userscontroller(); module.exports = userscontroller;
the error i'm getting console "cannot find module ./src/controllers/userscontroller.js". tried type absolute location of file inside require , got same error, must failing somewhere else.
thanks in advance
paths relative files, not project root. example in controller should use '../models/user.js'
:
var usermodel = require('../models/user.js');
Comments
Post a Comment