i used glitch for my website html, im now switching to something else and want to know how it starts. is it like npm start or like node .? what is it?
What is something else, just curious ?
A different VPS. I’m currently just trying visual studio code and dont know how to run it.
Cannot Find Module. I just downloaded my project and tried node ., it just errors no module, what should I do?
Do you have a package.json ?
I’ll get it off of express like you said. One min.
Or do npm init on the terminal
okay, that worked, how do i get the url, do i console.log(process.env.PORT)?
edit: just says its undefined, how do i get my local host port?
What url ? @mynamecolt420
when you start up the website and you mostly get local host, how do i get that console logged so i know the url it has that i go to see it?
i got the port, but localhost:port dosent work.
Do u have an apache web server ?
im just trying to get the url to see my website and localhost port isnt working. what should i do? also I dont believe i have a apache web server im just trying to see my bot website off of visual studio code
Well, wich computer do you have? windows or Mac @mynamecolt420 . Its different for each computer
Can you view your logs? It often shows the port there.
I usually right-click on the main file (this matters on the type on project.) then press open with chrome or wich ever preferred search enigne you have
You can also use netstat
in the command prompt to see what ports are being used.
Your app is listening on port 56430, i get that, but on windows when i do localhost:56430 it shows nothing saying localhost didn’t send any data so how do i get the proper url to see it live? because before on my old version of the website localhost and this worked great, now it dosent.
what i said to river.
Cannot GET / when i try localhost, here is the code I think its erroring on.
**const express = require(“express”);
const app = express();
app.get("/index.html", (request, response) => {
response.json("/index.html")
});
app.listen(process.env.PORT);
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});
console.log(“started”);**
thats all i have in my script.js.
how would i fix this? @RiversideRocks
In that case, visit index.html
response.json("/index.html")?
What are you asking? You should also not use index.html in Express routing, you should use /
but then it says it cant find it?
Hello @mynamecolt420, what you need is an application to serve your static files over the internet, or your local network.
In almost every programming language there is a way to do that, however the one I find easiest is using Node.js and Express. After installing node you can open up a shell (command prompt or terminal), I suggest you navigate to a testing directory.
When you have a directory set for this you can start by executing the following commands:
npm init -y # Initiate a new project or package.
npm i -S express # Save express as one of your dependencies.
After that you can open up your preffered text editor and create a file called index.js
inside of that directory and write the following code:
// Fetch dependencies.
const Express = require("express");
// Create an express application.
const App = Express();
// Use a static site middleware provided by express.
App.use(Express.static(__dirname + "/public"));
// Start the web server.
App.listen(process.env.PORT || 3000, () => console.log("🚀 The server is listening on http://127.0.0.1:3000"));
Now create a file located in path/to/dir/public/index.html
<html>
<head>
<meta charset="utf-8" />
<title>My Static Webpage</title>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
The you run your app by running the following command node .
inside of the directory.
It is node .
or node yourservername.js
.
Thanks for clearing up the small confused mess of answers!