How do I convert my regular website into a node site

I was adding games to my website and the Offline Paradise game requires node modules. But normal websites don’t have npm installed in the glitch console What Do I Do?

1 Like

Hi there! So if I’m right, you appear to be saying that you want to use Node.JS on your site.

Node.Js is a SERVER-SIDE programming language, meaning the person that is on your website, does not see this.

Node.Js is NOT a CLIENT-SIDE programming language, so you technically don’t install NPM modules to the website.

You can create a Node Express project by hitting New -> Express Project.

I hoped this helped in some way!

Just to add to what @rossAPi was saying – you can run many npm packages in the browser, but you’ll want to use something like browserify or webpack to do so! Basically it takes serverside code and bundles it up to be sent to the client in a usable format.

If you have a frontend-only website on Glitch, and you would like to make it a Node app with both frontend and backend, add a package.json file to it - you do not have to start over by remixing ~hello-express.

When you add a package.json file, you need to start serving the frontend files that were previously served automatically. You can look at package.json and server.js in ~hello-express to see how to do that, but basically, you’re going to want to put everything that was in your frontend-only site into a public/ directory, and then with a line like ~hello-express uses in server.js:

app.use(express.static("public"));

You serve it as static content from the public/ directory.

Hope this helps,

Johnicholas

2 Likes

note: you won’t see the folders you add (e.g. node_modules). you’ll need to open the terminal/console, and use the refresh command to get them to show up. see: Hiddens folders/files from dashboard - #2 by NikoBotDev

1 Like