I am following this https://developers.facebook.com/docs/messenger-platform/quickstart tutorial to add a web hook.
It's written to use this app https://github.com/fbsamples/messenger-platform-samples
that app is a node js app.
in the app.js, there is this:
const
bodyParser = require('body-parser'),
config = require('config'),
crypto = require('crypto'),
express = require('express'),
https = require('https'),
request = require('request');
when i run the app like this:
node app.js
i get the following error:
module.js:327
throw err;
^
Error: Cannot find module 'body-parser'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\MyApps\messe
nger-platform-samples-master\node\app.js:14:16)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
how can I solve it please ?
Open terminal (or windows command line), go to messenger-platform-samples/node directory and install messenger-platform-samples by running this command:
npm install
after that you can run the app:
node app.js
First run npm install and this will rectify all errors
Run this command first
npm install -g body-parser
then create const bodyParser = require('body-parser')
Related
I'm trying to create a todo list App with passport authentication, but I get this error when I run node app:
module.js:549
throw err;
^
Error: Cannot find module 'mongoose-unique-validator'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/walid/Todo list API/models/user.js:2:23)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/walid/Todo list API/app.js:7:12)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
This is my App file, and the error says that it can't connect to mongoose:
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const expressValidator = require('express-validator');
const flash = require('connect-flash');
const session = require('express-session');
const config = require('./config/database');
const passport = require('passport');
mongoose.connect(config.database);
let db = mongoose.connection;
// Check connection
db.once('open', function () {
console.log('Connected to mongoDB');
});
Can anyone please help me?
Probably the mongoose library is utilizing mongoose-unique-validator , usually they install it in their inner package.json but looks like something is wrong. Try to install it yourself.
The module mongoose-unique-validator that's mentioned in the error is a submodule of mongoose. It's possible that it didn't get installed when you installed the mongoose module.
You can try reinstalling by typing one of the following:
Yarn
yarn add mongoose
NPM
npm install mongoose
I have installed serialport using npm, but why its failing to connect?
$ ls /dev/tty.*
/dev/tty.Bluetooth-Incoming-Port /dev/tty.usbserial-AI0255BX
$ cat /var/tmp/test.js
var SerialPort = require('serialport');
var port = new SerialPort('/dev/tty.usbserial-AI0255BX', {
baudRate: 57600
});
$ node /var/tmp/test.js
module.js:471
throw err;
^
Error: Cannot find module 'serialport'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/private/var/tmp/test.js:1:80)
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)
Nodejs search package.json in the same folder as the script. If it does not found it search in the parent folder etc...
I see in your pastbin that you have install the node module in your home, so package.json is unattainable for Node.
You can try this :
npm install -g serialport
The -g (global) option permit to use the bin no matter where you are.
Or :
Move your script in the same folder (or subfolder) where is your package.json
Hello I am new in a nodejs and when I run any file in command prompt like:-
C:\demoData>node demo.js
I get error li9ke this
module.js:327
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\demoData\shahzad.js:1:77)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
I did R&D and get the solution
npm install express
And my Problem has solved using this. But Why I required this I have already express folder globally.this path
C:\Users\broswire\AppData\Roaming\npm\node_modules;
I want to use this node_modules, I don't want locally node_modules.
Node encourages using locally installed modules. Generally, using modules installed with npm install --global or npm install -g should be reserved for cli tools and things used systemwide. So to use express in a project, it is recommended to npm install express in that directory. It is also useful to add a package.json file to save the versions of your dependencies. Then you can just navigate to your project and run npm install and it will install the required dependencies.
I am running a JavaScript code on Ubuntu server using node.js
I got this error.
module.js:340
throw err;
^
Error: Cannot find module './lib/compat'
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> (/usr/lib/nodejs/node_modules/express/node_modules/depd/index.js:11:24)
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)
How to debug this error?
Edit: using these dependencies.
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
The problem can persist even after running:
npm uninstall express
npm install express --save
If this happens delete the node-modules folder and then run:
npm install express
and
npm install
to reinstall all the packages listed in packages.json
The problem is not directly in your code, but in the dependency of one of the modules you're using. You see it at this line of the error message:
at Object.<anonymous> (/usr/lib/nodejs/node_modules/express/node_modules/depd/index.js:11:24)
express module has a dependency called depd, which is the module in trouble.
How did you install your modules?
There has probably been some problem when you have installed express.
The folder lib/compat is directly part of depd, so there's no reason it should be missing.
You may want to do the following:
npm uninstall express
npm install express --save
This would reinstall express, hopefully solving the issue.
I am trying to connect to redis in linux using node js as below
var redis = require('redis');
But, getting the error as below.
I have redis-2.4.17 installed in linux and the path is /home/masadmin/redis-2.4.17/src
Kindly help on how to connect to redis using node in linux.
module.js:340
throw err;
^
Error: Cannot find module 'redis'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/masadmin/Vinod/prapprRedisLoad.js:2:13)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
Have you installed the Node.js Redis module for your application? npm install redis (in the same directory as your application) will install it. Check out this screencast for more information.
I have the same error after Node.js Redis module has been installed.
I've fixed it (error) after changing NODE_PATH environment variable:
export NODE_PATH=$NODE_PATH:<YOUR_NODE.JS_HOME>/node_modules