因此我尝试创建一个基本上注册您的网页,然后向您发送确认电子邮件。我面临一个断言错误。能不能有人告诉我哪里出错了以及错误发生的原因?
P.S:我将审查我的私人信息,如电子邮件,sendgrid ID&通过 谢谢..
错误:
> test@0.0.0 start /Library/nodeJs/test
> node ./bin/www
assert.js:86
throw new assert.AssertionError({
^
AssertionError: missing path
at Module.require (module.js:363:3)
at require (module.js:384:17)
at Object.<anonymous> (/Library/nodeJs/test/routes/newuser.js:3:16)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Library/nodeJs/test/app.js:32:21)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.5
npm ERR! npm v2.11.2
npm ERR! code ELIFECYCLE
npm ERR! test@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls test
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Library/nodeJs/test/npm-debug.log
App.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var routes = require('./routes/index');
var users = require('./routes/users');
var fs=require("fs")
var app = express();
var multer=require("multer");
var crypto=require("crypto");
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//mongoose.connect('mongodb://localhost/adithya');
app.use('/', routes);
app.use('/users', users);
app.use('/newuser', require('./routes/newuser'));
mongoose.connect('mongodb://localhost/registration', function(err) {
if(err) {
console.log('connection error', err);
} else {
console.log('connection successful');
}
});
//multer
var done=false;
/*Configure the multer.*/
/* app.get('/users',function(req,res){
mongoose.model('users').find(function(err, users){
res.send(users);
});
}); */
fs.readdirSync(__dirname + '/models').forEach(function(filename) {
if (~filename.indexOf('js')) require(__dirname + '/models/' + filename)
console.log("fileread");
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
index.JS
var express = require('express');
var multer = require("multer");
var router = express.Router();
router.get('/', function(req, res) {
res.render('index.ejs', { title: 'Express' });
});
module.exports = router;
user.js(routes)
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var users = require("../models/users")
/* GET users listing. */
router.get('/', function(req, res, next) {
console.log("inside get function");
users.find(function(err, users){
res.send(users);
});
});
module.exports = router;
user.js(models)
var mongoose= require("mongoose");
var Schema= mongoose.Schema;
var usersSchema = new Schema({
username: String,
email: String,
password: String,
status: Number
});
mongoose.model("users",usersSchema);
newuser.js
var express= require('express');
var router= express.Router();
var mongoose = require(mongoose);
router.get('/', function(req, res) {
console.log("username : " + req.body.username+", email : "+ req.body.email+ ", password : " + req.body.password );
var newUser= users({
username: req.body.username,
email: req.body.email,
password: req.body.password,
status: '0'
});
newUser.save(function(err){
if(err) throw(err)
var Cryptr = require("./cryptr");
cryptr = new Cryptr('myTotalySecretKey');
var encryptedString = cryptr.encrypt(req.body.username);
var sendgrid = require('sendgrid')("Username", "Password");
var email = new sendgrid.Email({
to: req.body.email,
from: 'fromID',
subject: 'Registration',
text: "Pls click on the following link to confirm https:/localhost:3000/confirmation?username="+ encryptedString
});
sendgrid.send(email, function(err, json) {
if (err) { return console.error(err); }
console.log(json);
});
res.send("ok");
});
});
答案 0 :(得分:2)
这是一个简单的语法错误。我键入var mongoose = require(mongoose);
而不是var mongoose = require("mongoose");
我的IDE没有指出这一点。
谢谢