Confused about npm packages in nodester
I’m new to node and having trouble understanding how nodester deals with npm packages. When I use the command nodester npm install package-name
in the CLI, I can’t find any packages in my app’s folder. Can I still use these packages like normal even though I can’t see them?
I’ve been told not to keep packages in my folder to save space, since nodester is a free Node PaaS. But this is making things confusing for me.
Also, I want to run my app both on my computer and on nodester. How do I stop git from pushing my local node_modules? I’ve heard about something called gitignore but I’m not sure how to use it.
Sorry if this isn’t clear. I’m still learning and would appreciate any help or clarification. Thanks!
Having worked with Nodester for a while, I can shed some light on this. Nodester’s approach to npm package management is quite clever, actually. It uses a centralized package cache to optimize space and improve deployment speed.
When you run that nodester npm install
command, the packages are indeed installed, but they’re stored in a shared location on the server. Your app can access them at runtime without needing them in your project directory. This setup saves space and speeds up deployments.
For local development, I’d recommend using npm as usual. Create a package.json file if you haven’t already, and install packages locally. Then, use a .gitignore file to exclude node_modules from your Git repo.
One tip I’ve found helpful: keep your package.json and package-lock.json files in version control. Nodester uses these to know which packages your app needs. This way, you can develop locally with full access to your node_modules, while Nodester handles the server-side package management efficiently.
Nodester handles npm packages a bit differently than your local environment. When you run nodester npm install package-name
, the packages are installed in a shared directory on the server rather than directly in your app’s folder. This method helps conserve space while still allowing your app to access the packages at runtime.
For local development, creating a .gitignore
file and adding node_modules/
there prevents Git from tracking these dependencies. Additionally, maintaining a package.json
file is vital. You can generate it by running npm init
locally, and then add dependencies with npm install --save package-name
. This file is used by Nodester to install the correct packages on the server.
While this setup may seem unconventional at first, it becomes more intuitive as you continue to work with it, ensuring efficient package management across different environments.