Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't start my Server because TypeError

I tried to start my server, but it do not work because a TypeError occurred, as you can see down below:

    TypeError: Status.methods is not a function
at Object.<anonymous> (/Users/elmo/Documents/AndroidApp-Projekte/AbHofAPI/routes/api.js:9:8)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/elmo/Documents/AndroidApp-Projekte/AbHofAPI/server.js:15:17)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
    [nodemon] app crashed - waiting for file changes before starting...

My code is the following:

server.js

//dependencies:
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');

//connect to mongoDB
mongoose.connect('mongodb://mydbuser:[email protected]:25914/abhofdata');

//express:
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

//routes:
app.use('/api', require('./routes/api'));

//start server:
app.listen(1000);
console.log('Server is running on port 1000');

api.js

//dependencies:
var express = require('express');
var router = express.Router();

//get models: 
var Status = require('../models/status');

//routes:
Status.methods(['get', 'post', 'put', 'delete']);
Status.register(router, '/status');

//return router:
module.exports = router;

status.js

This Class contains the Schema, which outlines how the data is stored in mongoDB.

//dependencies:
var restful = require('node-restful');
var mongoose = restful.mongoose;

//Schema:
var statusSchema = new mongoose.Schema({
name: String,
strasse: String,
ort: String,
lat: String,
lng: String,
info: String
});

//return models:
module.export = restful.model('tblstatus', statusSchema);

folder structure

Perhaps the folder structure is important for a solution. Here it is:

AbHofAPI
│   package.json
│   server.js    
│
└───node_modules
│
└───models
│   │   status.js
│   
└───routes
    │   api.js
like image 774
elmo Avatar asked Aug 22 '26 01:08

elmo


1 Answers

you did module.export = ..

you need module.exports = ..

like image 197
user943702 Avatar answered Aug 24 '26 15:08

user943702