Parse server clone install - javascript

I clone Repo parse server from parse-server-example and add run mongo db and also install nodejs pacakge via npm install, But when i want to run app with npm start print this error in terminal!!
How i can fix this issue ? it's about nodejs version or what?
Here is my index.js file:
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'app',
masterKey: process.env.MASTER_KEY || 'master', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
var app = express();
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('Make sure to star the parse-server repo on GitHub!');
});
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
And by install babel-cli and run show me this:
/Users/sajad/Sites/parse/node_modules/parse-server/node_modules/babel-polyfill/lib/index.js:14
throw new Error("only one instance of babel-polyfill is allowed");
^
Error: only one instance of babel-polyfill is allowed
at Object.<anonymous> (/Users/sajad/Sites/parse/node_modules/parse-server/node_modules/babel-polyfill/lib/index.js:14:9)
at Module._compile (module.js:460:26)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:134:7)
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> (/Users/sajad/Sites/parse/node_modules/parse-server/lib/ParseServer.js:9:1)
at Module._compile (module.js:460:26)

This is because this module(or more correctly, a dependency of your module) is using the const keyword which isn't available in your node version (v0.12). Full support for the const keyword came in v6 of node which arrived just this week.
Alternatively you could transpile your project using babel
If you go with the babel route you could do the following in your project root folder
npm install -g babel-cli
babel-node index.js
See babel usage page for more information on how to use babel correctly.
EDIT: In the documentation you provided it explicitly tells you that you must have at least node v4.3 and that you should run the project with the command "npm start". So i'm guessing that this project already has babel, you're just running it incorrectly and with the incorrect node version.

Related

Address Info Syntax Error Node.js (Express)

I am making a server using TypeScript that my angular app can connect to, but I get the following error when I try to run it: (PS I tried using destructuring with the AddressInfo, but Node.js or TS is not compatible yet with ES6 features)
const {address, port} = server.address() as AddressInfo;
^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
at internal/main/run_main_module.js:17:11
The code below:
const express = require('express');
const AddressInfo = require('AddressInfo');
const app = express();
app.get('/', (req, res) => res.send('Hello from Express'));
app.get('/products', (req, res) => res.send('Got a request for products'));
app.get('/reviews', (req, res) => res.send('Got a request for reviews'));
const server = app.listen(8000, "localhost", () => {
const {address, port} = server.address() as AddressInfo;
console.log(`Listening on ${address}:${port}`);
});
The as key word is not vanilla JavaScript, it is TypeScript,also Node.js runs JavaScript, if you need to use TypeScript you can use the the node Typescript package it allows you to transpile .ts files into .js or use babel
I am making a server using TypeScript
More accurately, you are making a server using NodeJS. Node only natively supports JavaScript. The quick fix here is to remove as AddressInfo since this is TypeScript syntax, not JavaScript.
If you really want to use TypeScript instead of JavaScript, you need to rename your .js files to .ts and configure NodeJS to use TypeScript.

twilio error 'username required'

var express = require('express');
var router = express.Router();
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');
var TWILIO_TOKEN = "270ff32fe16828869dc30e0c6926fa9e";
var client = require('twilio')(process.env.AC55a59221acb23a5aa6f046740bb73317, process.env.TWILIO_TOKEN);
router.use(bodyParser.urlencoded({extended: true}));
router.use(bodyParser.json());
router.post('/', function(req, res) {
console.log('this is the req', req.body);
client.messages.creat({
to:'+19522209630',
from:'+17633249718',
body:'hello World'
}, function(err, data) {
if (err) {
console.log('err', err);
console.log('data', data);
}
});//en d of sendMessage
res.send(200);
});
module.exports = router;
/Users/moisesmiguelhernandez/Documents/prime/solo_project/node_modules/twilio/lib/rest/Twilio.js:101
throw new Error('username is required');
^
Error: username is required
at new Twilio (/Users/moisesmiguelhernandez/Documents/prime/solo_project/node_modules/twilio/lib/rest/Twilio.js:101:11)
at initializer (/Users/moisesmiguelhernandez/Documents/prime/solo_project/node_modules/twilio/lib/index.js:8:10)
at Object.<anonymous> (/Users/moisesmiguelhernandez/Documents/prime/solo_project/routes/sendMessage.js:6:31)
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 Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/moisesmiguelhernandez/Documents/prime/solo_project/server.js:10:19)
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)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! solo_project#1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the solo_project#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/moisesmiguelhernandez/.npm/_logs/2017-07-11T15_02_02_750Z-debug.log
I am getting and error that says username is required. I am trying to use twilio. I followed a youtube video and i have it like he does. Any suggestions on how to fix this? P.S The index file is the terminal error message
Save these into a .env file at your root of your folder
TWILIO_TOKEN = "270ff32fe16828869dc30e0c6926fa9e"
TWILIO_ACCOUNT_SID = "AC55a59221acb23a5aa6f046740bb73317"
Then install
npm install dotenv --save
After that you can use these environment variables in your file like this:
require('dotenv');
var client = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_TOKEN);```
I had this same issue as well. What fixed it for me is doing
npm install dotenv
require('dotenv').config()
then I added my
TWILIO_ACCOUNT_SID=***
TWILIO_AUTH_TOKEN=***
full code:
require('dotenv').config();
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.calls
.create({
url: 'http://demo.twilio.com/docs/voice.xml',
to: process.env.CELL_PHONE,
from: process.env.TWIL_NUM,
})
.then(call => console.log(call.sid))
.catch(err => console.log(err));
var TWILIO_TOKEN = "270ff32fe16828869dc30e0c6926fa9e";
var TWILIO_ACCOUNT_SID = "AC55a59221acb23a5aa6f046740bb73317";
var client = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_TOKEN);
#philnash i changed it and fixed the creat typo but the terminal is still saying 'username is required'
Note -: This is not at all a good way but just a workaround. I will edit the answer as soon I will get the right way. This is just a trick which worked in my case.
const client = require('twilio')(<YOUR_ACCOUNT_SID>, <YOUR_ACCOUNT_KEY>);
basically use the keys directly instead of referencing through any variable.
Twilio developer evangelist here.
Aside from the typo in creat that Champa has pointed out in the comments, I think I know where you're going wrong. Your code currently has:
var client = require('twilio')(process.env.AC55a59221acb23a5aa6f046740bb73317, process.env.TWILIO_TOKEN);
I am guessing that it should have something like process.env.TWILIO_ACCOUNT_SID.
The account sid is effectively the username for accessing the API, which is why the error message says that.
Let me know if that helps at all.
I encountered this issue today and was getting message Error: username is required when running my twilio test. Since I am using dotenv, I have a .env file with my environment variables, and this is where I made a mistake. We have another app with the SID and TOKEN variables, so I copied them and left in the export keyword, i.e. export TWILIO_ACCOUNT_SID=..., but if using dotenv, the export keyword is not needed. I removed export and re-run my test script and it all worked, e.g.
TWILIO_ACCOUNT_SID=***
TWILIO_AUTH_TOKEN=***
I was working with a colleague when we encounter the same error. I tried almost all the solutions but didn't work for me (most of the solutions here are the same in a sense).
How we resolve this was amazing: how?
When you are using a file called .env for your environment variables, you need to double checks where you created this file
.env file must be created in your root directory. That means must be inside your project folder not inside sub-folder that is inside your project.
when you are to use it, make sure you reference the right variable. This mistake is
related to this question. such as
// index.js
// this wrong, notice process.env.AC55a59221acb23a5aa6f046740bb73317 in client variable
TWILIO_TOKEN = "270ff32fe16828869dc30e0c6926fa9e";
var client = require('twilio')(process.env.AC55a59221acb23a5aa6f046740bb73317, process.env.TWILIO_TOKEN);
this is correct process.env.TWILIO_ACCOUNT_SID
// .env
TWILIO_ACCOUNT_SID=AC55a59221acb23a5aa6f046740bb73317
Twilio Documentation
Interested in the mistake we made, it's the wrong placement of .env file.
I have ran into this error earlier so, adding to the answers above make sure the .env file is in the root directory, all spellings are correct and dotenv package is used.
I figured out the issue that I was having with this. When starting up the server, make sure that you are in the directory that contains the .env file.
The Silly mistake which I made was, I used "SMS_SID: YourSID", It must be "SMS_SID = YourSID".
In my case, everything was correct except I was using the account_sid and auth_token of test credential instead of Live credential.

"TypeError: undefined is not a function" when requiring jQuery-ui in node.js using Express

I am trying to set up a small node.js webserver which will use jQuery and jQuery-ui. I have used Express to set up a small project and then installed all packages I need using npm <package-name> install --save. Please bear in mind that I am new to the JavaScript world, so I might be doing silly things, but I could not find anyone with the same issue (just related).
Express has set up the project like this:
$ ls
app.js bin node_modules npm-debug.log package.json public routes views
The folder node_modules now contain:
$ ls node_modules
body-parser cookie-parser debug express jade jquery jquery-ui morgan serve-favicon
My app.js file is as set up by Express except that I now include jQuery and jQuery-ui, like this:
$ cat 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 jQuery = require('jquery');
var jQueryUi = require('jquery-ui');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
// The rest is omitted here for brevity. Default settings from Express.
Running node bin/www now shows the error
/home/oystein/QAWebApp3/node_modules/jquery-ui/jquery-ui.js:15
$.extend( $.ui, {
^
TypeError: undefined is not a function
at /home/oystein/QAWebApp3/node_modules/jquery-ui/jquery-ui.js:15:3
at Object.<anonymous> (/home/oystein/QAWebApp3/node_modules/jquery-ui/jquery-ui.js:316:3)
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> (/home/oystein/QAWebApp3/app.js:8:16)
at Module._compile (module.js:460:26)
This error seems to originate from the file jquery-ui.js, which looks like this:
var jQuery = require('jquery');
/*! jQuery UI - v1.10.3 - 2013-05-03
* http://jqueryui.com
* Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js, jquery.ui.effect.js, jquery.ui.accordion.js, jquery.ui.autocomplete.js, jquery.ui.button.js, jquery.ui.datepicker.js, jquery.ui.dialog.js, jquery.ui.effect-blind.js, jquery.ui.effect-bounce.js, jquery.ui.effect-clip.js, jquery.ui.effect-drop.js, jquery.ui.effect-explode.js, jquery.ui.effect-fade.js, jquery.ui.effect-fold.js, jquery.ui.effect-highlight.js, jquery.ui.effect-pulsate.js, jquery.ui.effect-scale.js, jquery.ui.effect-shake.js, jquery.ui.effect-slide.js, jquery.ui.effect-transfer.js, jquery.ui.menu.js, jquery.ui.position.js, jquery.ui.progressbar.js, jquery.ui.slider.js, jquery.ui.spinner.js, jquery.ui.tabs.js, jquery.ui.tooltip.js
* Copyright 2013 jQuery Foundation and other contributors; Licensed MIT */
(function( $, undefined ) {
var uuid = 0,
runiqueId = /^ui-id-\d+$/;
// $.ui might exist from components with no dependencies, e.g., $.ui.position
$.ui = $.ui || {};
$.extend( $.ui, {
version: "1.10.3",
keyCode: {
BACKSPACE: 8,
COMMA: 188,
DELETE: 46,
DOWN: 40,
// Lots of other defines...
})( jQuery ); // End of block on line 316
My guess is some inclusion problems. The error kicks in at line 15, $.extend( $.ui, {, but the message tells me to look at the line (function( $, undefined ) {. What is the best way to solve this?
Oh, and package.json looks like this:
{
"name": "QAWebApp3",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "^1.12.3",
"cookie-parser": "^1.3.4",
"debug": "^2.1.3",
"express": "^4.12.3",
"jade": "^1.9.2",
"jquery": "^2.1.3",
"jquery-ui": "^1.10.5",
"morgan": "^1.5.2",
"serve-favicon": "^2.2.0"
}
}
To be used on the client, jQuery and jQuery-UI files should be served as static files on the server, and Express has a static middleware for that which you could use to define a directory to look for static files in. More here.
These files could be downloaded from jQuery site or managed with client package manager like Bower, since it appears jQuery-UI from npm is using require which is not supported on browsers.
You could also use hosted jQuery files so you would not need to have it on the server.
Then a <script> tag should be added to your html (or Jade) files to load and use them.
jQuery and jQuery-UI are meant to be used in the front-end and are not expected to work with Node without the DOM. If you want to use any of the helper jQuery functions you could use underscore.js which contains similar functionality.
If you want to create some HTML UI to be return by your express server, then both libraries (jQuery and jQuery-UI) should be defined/included (using the tag) within your template files (jade files).
Hope this helps

MongoDB - Error: Cannot find module '../build/Release/bson'

I tried to run a typescript example in the following way which caused following error:
$ mongod --dbpath /home/u/databases
$ npm install
$ tsc --sourcemap --module commonjs app.ts
$ node app.js
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
========================================================================================
= Please ensure that you set the default write concern for the database by setting =
= one of the options =
= =
= w: (value of > -1 or the string 'majority'), where < 1 means =
= no write acknowledgement =
= journal: true/false, wait for flush to journal before acknowledgement =
= fsync: true/false, wait for flush to file system before acknowledgement =
= =
= For backward compatibility safe is still supported and =
= allows values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}] =
= the default value is false which means the driver receives does not =
= return the information of the success/error of the insert/update/remove =
= =
= ex: new Db(new Server('localhost', 27017), {safe:false}) =
= =
= http://www.mongodb.org/display/DOCS/getLastError+Command =
= =
= The default of no acknowledgement will change in the very near future =
= =
= This message will disappear when the default safe is set on the driver Db =
========================================================================================
/home/u/tmp/TypeScriptSamples/imageboard/app.js:9
app.configure(function () {
^
TypeError: Object function (req, res, next) {
app.handle(req, res, next);
} has no method 'configure'
at Object.<anonymous> (/home/u/tmp/TypeScriptSamples/imageboard/app.js:9:5)
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)
at startup (node.js:119:16)
at node.js:929:3
Furthermore, looking at db.ts I think http and url are missing in package.json file, am I right?
How is it possible to fix the above error with mongodb?
in Linux operating system first remove bson folder from node_modules and run this command:
sudo apt-get install gcc make build-essential
and then restart nodejs file such as index.js. Hope its helpful
I am using connect-mongo for sessions. I had the same problem and was because the version of connect-mongo generated an error with the version 4.0.x of mongoose. You could check each version of the dependencies you are using.
looking at db.ts I think http and url are missing in package.json file, am I right?
No. These modules are a part of core nodejs.
The source of the error is the package.json specifying minimum numbers without backward in compatible version locks. https://github.com/Microsoft/TypeScriptSamples/blob/master/imageboard/package.json#L6 I would change '>=' to be harder versions e.g. 3.x

cannot find socket.io-client on nodejs server running

clean install node ,express, socket.io on linux environment using npm. I try to runsocket.io sample from socket.io official source, I am getting error socket.io-client module not found on command line.
I work around few hours to solve this. but I didnt found any soutions.
Error :
module.js:337
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module 'socket.io-client'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (/home/rajuk/Documents/nodeSamples/node_modules/socket.io/lib/socket.io.js:12:14)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:32)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
socket.io install result
socket.io#0.9.14 /usr/local/lib/node_modules/socket.io
├── base64id#0.1.0
├── policyfile#0.0.4
├── redis#0.7.3
└── socket.io-client#0.9.11
here is my code(app.js)
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
server.listen(80);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
and node_modules directory contains socket.io and express packages.
I am trying to run server like this
$ node app.js
how to resolve it?
Clone this git depositery : https://github.com/yrezgui/socket.io-simple-demo
And tell me if you still have an error.

Categories

Resources