No server side output

I have a new project, with it’s main.js

if(Meteor.isServer){
console.log(“Hello SERVER”);
}

In my terminal (windows7) I see not output.why is that?

Where is the ‘main.js’ file located in your folder structure?

Is it located within/underneath a ‘client’ or ‘imports’ folder by chance?

It’s a new project, so the default location, is under client.
There is no import folder…

Files within the ‘client’ folder will not run at all on the server (server side output is displayed in the terminal, client side output is displayed in browser console). You need to move your main.js outside the ‘client’ folder. It should then behave as expected.

See here for more info on Meteor’s special directories/folders:

https://guide.meteor.com/structure.html#special-directories

1 Like

Im reading an ebook thats probably old. I moved my code into the main.js under server folder and problem solved. Is the isserver conditional deprecated into those two main.js files under client and server folders? Where do i write code thats is to run on both? Why dont i have an import directory? Can u recommend a beginers tutorial that is updated? Thanks

Meteor.isServer has not been deprecated, so you can still use it.

For code to run on both server and client you put it anywhere as long as it’s not within a folder called ‘client’ or ‘server’.

If you’re just starting out with Meteor and Javascript, don’t worry too much about the imports folder at this stage, that will come later.

Discover Meteor is probably your best bet for an intro to Meteor, even though it doesn’t cover the very latest stuff it will give you a great starting point, then you can then move onto the official Meteor guide to level up your knowledge.

To follow up – while code wrapped in Meteor.isServer will only run on the server, it can still be bundled with client/shared code, exposing potentially sensitive code. It’s usually best to keep your client/server code separate.

1 Like

Thanks for the reply. So should i create a main.js in the root folder to run code on both server and client?

You can check out the recommended structure, or if you are just getting started, you can use the /client and /server folders in your app root to restrict code to either the client or server. Shared code can go in another top-level folder, like /lib.

1 Like