Node js , Error: can not find module - javascript

Here is the error which I get when I run nodejs app.js
module.js:340
throw err;
^
Error: Cannot find module 'share'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/quicksilver/project/master/app.js:3:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
I am repeatedly getting this error :
I have already done npm install -g share several times ,but it has been no use.
var express = require('express')
var sharejs = require('share')
var connect = require('connect')
var AWS = require('aws-sdk');
//var zmq = require('zmq');
var app = express();
app.set('view options', {layout: false});
var problem={};
var sharejs_server;
AWS.config.loadFromPath('./awsconfig.json');
locomotive.boot('.', app.settings.env, function(err, app) {
var options = {};
if (err) { throw err; }
options.db = app.locals.db;
sharejs_server = sharejs.server.attach(app, options);
app.listen(app.locals.port, app.locals.ip, function () {
var addr = this.address();
console.log('listening on %s:%d', addr.address, addr.port);
});
});

Related

Cannot find module (Error: Cannot find module './models/campground')

this is my code
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose"),
Campground = require("./models/campground"),
Comment = require("./models/comment"),
seedDB = require("./seeds")
this are my file's tree
and when i run the above code, i get this error,
Error: Cannot find module './models/campground'
Require stack:
- /workspace/webDevBootcamp/yelpcamp/v4/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/workspace/webDevBootcamp/yelpcamp/v4/app.js:5:19)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/workspace/webDevBootcamp/yelpcamp/v4/app.js' ]
}
Replace
Campground = require("./models/campground"),
By
Campground = require("./models/campgorund"),
Or change the filename "campgorund.js" to "campground.js".
:)

koa-router error router.routes is not a function

When I try to use koa-route 3.2.0 example from their website, I got error message router.routes is not a function
const Koa = require('koa');
const router = require('koa-route');
const app = new Koa();
app.use(logger());
router.get('/users', (ctx, next) => {
ctx.response.body =`<h1>Hello!</h1>`;
});
app.use(router.routes())
.use(router.allowedMethods());
// don't listen to this port if the app is required from a test script
if (!module.parent) {
app.listen(1337);
console.log('listening on port: 1337');
}
I got error message:
app.use(router.routes())
^
TypeError: router.routes is not a function
at Object.<anonymous> (/Projects/shoucast-front-end-prototype/script/server.js:40:16)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
When I try to change
const router = require('koa-route');
to
var router = require('koa-router')();
I got error message:
const router = require('koa-route')();
^
TypeError: require(...) is not a function
at Object.<anonymous> (/Projects/shoucast-front-end-prototype/script/server.js:2:36)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
Looks like you've installed the newer version, available at https://github.com/alexmingoia/koa-router/tree/master
You need to use new Router() instead.
Also looks like you're mixing up koa-router with koa-route, which are two different packages.
const Koa = require('koa');
const Router = require('koa-router');
const app = new Koa();
const router = new Router();
router.get('/', function (ctx, next) {
// ctx.router available
});
app
.use(router.routes())
.use(router.allowedMethods());

Error: Cannot find module in node js

I want to add logInPageTest.js in a file with the require field, but when I am adding it , it is throwing this error.
module.js:472
throw err;
^
Error: Cannot find module './test-cases/logInPageTest.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/app/PycharmProjects/AutomationAppTesting/automationTest/index.js:15:15)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
Hierarchy is as follows:
-AutomationAppTesting
--automaitonTest
---test-cases
----logInPageTest.js
---index.js
Here is my code in index.js file:
require('./test-cases/logInPageTest.js')
Code in logInPageTest.js file:
var wd = require('wd');
var assert = require('assert');
module.exports = function (browser, next) {
maximizeWindow(browser, next);
}
function maximizeWindow(browser, next) {
browser .windowHandle( function (err, handle) {
browser.maximize(handle);
})
}
So, How should I give path to solve the error.

Cannot find module 'require'

this is the error below
E:\freelancer-work-backup\scraping>node index.js
Screenshot of error
$ node index
module.js:341
throw err;
^
Error: Cannot find module 'require'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (E:\freelancer-work-backup\scraping\index.js:1:83)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
Code in index.js:
var request = require('require'),
cheerio = require('cheerio');
var url = 'grocermax.com/catalogsearch/result/…';
request(url, function(err, resp, body) {
if (!err && resp.statusCode == 200) {
console.log(body);
} else {
console.log("Failed");
}
});
You should change the code to var request = require('request')

Mongoose Mixed Schema not working

I am trying to set mixed Schema in ExpressJs I tried to use mongoose.Schema.Types.Mixed didn´t worked and tried explicit as shown bellow but unfortunately it fails with same error:
"C:\Program Files (x86)\JetBrains\WebStorm 9.0.3\bin\runnerw.exe"
"C:\Program Files (x86)\nodejs\node.exe" app.js
c:\Users\User\Desktop\nodekid\node_modules\node-restful\lib\model.js:247
app.getDetail = app.get;
^ TypeError: Cannot read property 'get' of undefined
at Function.Model.register (c:\Users\User\Desktop\nodekid\node_modules\node-restful\lib\model.js:247:22)
at Object. (c:\Users\User\Desktop\nodekid\routes\api.js:10:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (c:\Users\User\Desktop\nodekid\app.js:18:17)
at Module._compile (module.js:456:26)
Process finished with exit code 8
/**
* Created by User on 3/8/2015.
*/
var restful = require("node-restful");
var mongoose = restful.mongoose;
var storeSchema = new mongoose.Schema({
name: String,
products: [new mongoose.Schema({
name : String,
description : String
})]
});
module.exports = restful.model("store", storeSchema);
/**
* Created by User on 3/8/2015.
*/
var express = require("express");
var router = express().Router;
var stores = require ("../models/store");
stores.methods(["get","post","put","delete"]);
stores.register(router,"stores");
module.exports = router;
New Error:
c:\Users\User\Desktop\nodekid\node_modules\node-restful\lib\model.js:228
app[key](prefix + '/:id([0-9a-fA-F]{0,24}$)?', handlerlist);
^ TypeError: Object function createApplication() { var app = function(req, res, next) {
app.handle(req, res, next); };
mixin(app, EventEmitter.prototype, false); mixin(app, proto,
false);
app.request = { proto: req, app: app }; app.response = {
proto: res, app: app }; app.init(); return app; } has no method 'get'
at Function.Model.registerRoutes (c:\Users\User\Desktop\nodekid\node_modules\node-restful\lib\model.js:228:17)
at Function.Model.register (c:\Users\User\Desktop\nodekid\node_modules\node-restful\lib\model.js:248:8)
at Object. (c:\Users\User\Desktop\nodekid\routes\api.js:10:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (c:\Users\User\Desktop\nodekid\app.js:18:17)
The error was in api.js in setting routing:
var router = express().Router;
Just Change it with:
var router = express.Router();

Categories

Resources