Meteor js - unable to insert data on Mongo through console - javascript

I'm following an udemy course on Meteor.
Steps to replicate my problem:
1) On CMD:
meteor create Leaderboard
cd Leaderboard
meteor npm install
meteor run
(server starts, localhost:3000)
2) Then, I deleted the contents of main.css, main.html & main.js (under client folder).
3) Opened main.js and added the following line:
PlayersList = new Mongo.Collection('players');
On Chrome's console I typed 'PlayersList' and got the following:
M…o.Collection {_transform: null, _connection: Connection, _collection: LocalCollection, _name: "players", _driver: LocalCollectionDriver…}
THE PROBLEM
When I type this on console:
PlayersList.insert({ name: 'David', score: 0 });
This is the Error:
"eebRFhA9vbSfHzPKk"
meteor.js?hash=e3f53db…:930 insert failed: Method '/players/insert' not found
Why am I getting it? I followed the exact steps provided by the instructor. What's wrong here?

That error is caused by the collection not having been defined on the server, only on the client.
The default app created by meteor create app contains two main.js files, one in the client and one in server folder. These specially-named folders work exactly as you'd expect - the content in them is only loaded on the client or server. Apparently you added the collection definition only to the one in client. To fix this, if you put a file outside these specially-named folders - say create a folder named collections, and add a PlayersList.js file there and define your collection there, then it will be loaded by both and work.
Alternatively (this is the recommended method when developing a larger app) if you put the file that defines the collection into a folder named imports then you can import that to your server and client code separately, instead of Meteor auto-including it. You can read more about Meteor application structure here.

Try this :-
PlayersList._collection.insert({ name: 'David', score: 0 });

Related

How to deploy node.js application in cyberpanel?

I have my application developed in node.js, and I have cyberpanel installed on my server. I have seen many examples of how to deploy a node application in cyberpanel, but I have doubts about how to view it from the browser.
So far I have the following configuration in vHost:
context / {
type appserver
location /FOLDER/FOLDER/PROJECT_FOLDER/dist
binPath /usr/bin/node
startupFile index.js
appType node
maxConns 100
}
My application runs perfectly on port 3000 when I run it by console, but I need to list it on port 80 with cyberpanel.
Does anyone have an idea how to do it?
try the following steps. Essentially, the error lies in selecting the root document folder and allowing access to the application.
Create a Website using the normal CyperPanel menu. [https://cyberpanel.net/docs/2-creating-website/]
Upload your Node.Js files into the public_html folder of the website.
Enter the Open Lite Speed panel via port :7080 (you would need to enable the port on the firewall)
Navigate to VH Hosts > Your Domain > Context
Select App Server, for location using $VH ROOT instead of the hardcoded path worked.
Additionally, don't forget to enable the site on access control via allowing all IPs (*).
context / {
type appserver
location $VH_ROOT/public_html/
binPath /usr/bin/node
appType node
startupFile server.js //this is the name of your
appserverEnv 1
maxConns 100
accessControl {
allow *
}
rewrite {
}
ad
See I am going to answer point to point to the question
First of all cyberpanel by default only takes app.js file as its core file to run the application.
Second, How to change that default file pointing ?
context / {
type appserver
startupFile index.js // **NAME OF YOUR STARTUP FILE**
location /home/PROJECT_FOLDER/public_html/dist
binPath /usr/bin/node
appType node
appserverEnv 1
maxConns 100
accessControl {
allow *
}
rewrite {
}
ad
location /FOLDER/FOLDER/PROJECT_FOLDER/dist
Note :- Things, I want to mention about this location parameter is this is the location to the your startup file, you will get it via file manager, as you cannot run typescript code directly here, you have to convert it into javascript using tsc command and further target dist folder using location parameter in vconfig file
Now next question is how to run application outside console ?
Create a website to deploy the project, use below link for reference click here
Issuing SSL for website - link for reference
This is my folder structure for deployment, simply zip all files and upload it on file manager of cyber panel, and extract out your files. You can see, I have dist folder which contains all javascript files and also have index.js, the main startup file.
Click on fix permissions on file manager.
Go to Web terminal and install node modules. how ?
on web terminal :- type cd .. and press enter.
There you have to find out your project from directory, You can use ls command to get list of files and folder structure.
mine directory was (after using cd ..) :- cd home/FOLDERNAME/public_html
At last run your project through terminal, to check its working.
Config your vhost config file, below is reference image
File you have to add in vhost config, I also had provided you above.
If you domain is setup correctly, you can view on api on your domain else you can click on preview button on cyber panel
Note :- Always Run code in terminal first to check its working.

4 FOSJSRouting callback=fos.Router.setData & Route not found in production only

I am developing a page within Symfony 4 that requires the FOSJSrouting bundle. Within my DEV environment - using docker - I got it working fine using the steps below.
However, in my prod environment I keep getting the errors:
- http://url/js/routing?callback=fos.Router.setData 500 (Internal Server Error)
- router.min.js:1 Uncaught Error: The route "get_coinTicker_from_platform" does not exist.
My steps to get it working in DEV:
$ composer require friendsofsymfony/jsrouting-bundle
Adding the following to routes.yaml:
fos_js_routing:
resource: "#FOSJsRoutingBundle/Resources/config/routing/routing.xml"
Adding the following to my base.html.twig
<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
This was sufficient to get my exposed routes to work:
/**
* #Route("/ticker/{coin}/{plat}", name="get_coinTicker_from_platform", options={"expose"=true})
*/
Then in my JavaScript I did:
$.ajax({
method: 'POST',
url: Routing.generate('get_coinTicker_from_platform', {coin: coin.val(), plat: exch.val()})
}).done(function(data) {
$('.loader').hide();
}
});
I installed the routing bundle using composer on my Linux server and even tried the steps included in the docs to publish assets as well as dump routes like so:
bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json
I have checked the symfony and Apache logs. Nothing is hinting about this issue there. Everything else is running fine, just FOSrouting is causing trouble.
Also, I tried:
npm install fos-routing --save
This actually temporarily solved the issue, but the next day, after I did another rsync from my local repository it was broken again.
I had the same problem and it has been solved by giving the right rwxrwxrwx on the folder var/cache/prod.
I am a fair bit late to the party but anyway let's get into it.
I think your issue - as hinted by #Samiul Amin Shanto comes from cached content that is not wiped out before dumping the routes.
In prod environment, symfony caches the Router. So if you do not wipe the cache
and update your code with new actions in your controller for example, they won't
be available at all because the route is not referencing them yet.
Hopefully you somehow managed to find this out because at some point you did run cache:clear --env=prod
So I'm just putting out this response here for any other internet user who might come across this question.
Take care.
Just in case someone has the same issue, I also spent about 2 hours on this, the actual issue is the right permission on the var folder inside your symfony project. Just refer to symfony official docs for giving the right permission here!

Uploading node.js app in bluemix

I created a Node.js app that works locally. It contains various routes as well as a login/registration system. Everything is fine. I can login,register,and apply all requests(GET,POST,PUT,DEL) through postman!
Now I want to post that app in bluemix. I created a manifest.yml file as shown.
applications:
name: larissa-capstone
memory: 256M
disk_quota: 512M
buildpack: nodejs_buildpack
domain: mybluemix.net
command: node server/web-server.js
However after running the push command cf push,I get the following error.
Incorrect Usage. The push command requires an app name. The app name can be
supplied as an argument or with a manifest.yml file.
But I have the app's name in the manifest file. Why is this happening?
Thanks,
Theo.
The manifest.yml does not have the required format. The name needs to be preceded with a dash and the other lines need to be indented. Try something like this:
applications:
- name: larissa-capstone
memory: 256M
disk_quota: 512M
buildpack: nodejs_buildpack
domain: mybluemix.net
command: node server/web-server.js

cannot start nodejs web api hosted in Azure

Learning nodejs and started to created my own restful API using restify.
I have created a very simple server.js file which contains basically a hello world type example starting up like:
server.post('/api/messages', servicemanager.verifyFramework(), servicemanager.listen());
server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
which works fine locally. I cant hit http://localhost:3978 and I can test my API calls just fine calling http://localhost:3978/api/messages.
I have deployed my code into bitbucket and now I want to host these APIs in Azure using App Services.
My project structure is like so:
/topfolder
-/myproject
-/node_modules
-/node_modules...
server.js
package.json
index.html
When I setup the new app service in Azure, I can see that the deployment receives the code from BB, but the service never responds to my requests.
I have setup the home path of the app to live in: /site/wwwroot/topfolder/myproject and I can see the index.html when I navigate to http://myproject.azurewebsites.net so thats good.
I actually get a 404 error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
There are heaps of examples of how to setup continuous deployment using bitbucket and for the most part, they all seem to work, but my server.js file doesnt seem to be the getting called or starting up.
How can I debug whats going on here?
Is the packages.json file used in this scenario by Azure?
Thanks.
As the root directory path of the application hosted on Azure App Services, is D:\home\site\wwwroot. And about the nodejs application, the Azure fabric will find the entrance script in root directory like server.js. And the requests are handled via web.config in root directory. If there is missing server.js or web,config file, you will occur 404 error.
You can try to modify or your application's structure, like to:
-/node_modules
-/node_modules...
server.js
package.json
index.html
Then, you deploy your application to Azure via GIT or from BB, the Azure deployment task will run command npm install and generate the web.config wile in the root directory.
Any further concern, please feel free to let me know.

Generate one js file from all signalr js files

I had taken the code below form this tutorial initially: SignalR Getting Started Application that will create a chat room. I've cleaned the html code a little bit to get only the part that I am going to need. I verified chat is still working:
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.6.4.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/signalr/jquery.signalR-2.0.0.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var chat = $.connection.chatHub;
chat.client.broadcastMessage = function (name, message) {
console.log('name is: ' + name);
console.log('message is: ' + message);
};
$.connection.hub.start().done(function () {
chat.server.send("khaled7", "message9");
});
});
</script>
As you can there are 3 javascripts files and 1 script block:
Now, I need to join all these scripts into one single file and send that to my remote mobile clients. I'm still at the web side, so I started joining the files/script top down. Joining the top 2 worked OK, but once trying to add the 3rd (/signalr/hubs), I get a 404 error in my chrome console:
http://localhost:52528/HubSample/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&clientProtocol=1.3&_=1464332439400
It is imperative for me to join them all. How can I go around this error!?
"/signalr/hubs" is not a physical file, it's a dynamically generated JavaScript code.
SignalR creates the JavaScript code for the proxy on the fly and
serves it to the client in response to the "/signalr/hubs" URL.
What you want to do is to create a physical file for the SignalR generated proxy that you can add to your single file:
Install the Microsoft.AspNet.SignalR.Utils NuGet package.
Open a command prompt and browse to the tools folder that contains the SignalR.exe file. The tools folder is at the following location:
[your solution folder]\packages\Microsoft.AspNet.SignalR.Utils.2.1.0\tools
Enter the following command:
signalr ghp /path:[path to the .dll that contains your Hub class]
The path to your .dll is
typically the bin folder in your project folder.
This command creates a file named server.js in the same folder as signalr.exe.
Put the server.js file in an appropriate folder in your project, rename it as appropriate for your application, and add a reference to
it in place of the "signalr/hubs" reference.
The problem is that you'll have to do this for every change in your hubs. Every. Single. time.

Categories