So I'm at a lose here and really need some direction.
I've been following Microsofts 'Introduction To NodeJS' course on edX. We had to create a very simple RESTful blog api using express. I've been trying to get it to run on my namecheap shared hosting.
What I've done:
- Followed these instructions to install nvm with the latest stable version of node.
- Followed this question to get my express app to work with https
- Uploaded the app to the hosting server.
- SSH'd into the hosting server, ran
npm install
. - ran
node server.js
to start the server. Seems to start okay. - Try navigating to my website on the port the app is listening on
https://samkeene.co.uk:3000/blog-api
- Expecting to see "Hello World" but instead getting a timeout.
server.js
const routes = require('./routes');
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const errorhandler = require('errorhandler');
const https = require('https');
const fs = require('fs');
const path = require('path');
let store = {
posts: []
};
let key = fs.readFileSync(path.join(__dirname,'../../ssl/keys/c07f7_003d1_ecb06ccb2afcd72cfa43b6011c82464e.key'));
let cert = fs.readFileSync(path.join(__dirname,'../../ssl/certs/samkeene_co_uk_c07f7_003d1_1574035199_5b90fc5e96ac0c534d2ee116af6fd342.crt'));
let options = {
key: key,
cert: cert
};
let app = express();
app.use(bodyParser.json());
app.use(logger('dev'));
app.use(errorhandler());
app.use((req, res, next) => {
req.store = store;
next();
});
app.get('/', (req, res) => {
res.send('hello world')
});
app.get('/posts', routes.Posts.getPosts);
app.post('/posts', routes.Posts.addPost);
app.put('/posts/:postID', routes.Posts.updatePost);
app.delete('/posts/:postID', routes.Posts.removePost);
app.get('/posts/:postID/comments', routes.Comments.getComments);
app.post('/posts/:postID/comments/', routes.Comments.addComment);
app.put('/posts/:postID/comments/:commentID', routes.Comments.updateComment);
app.delete('/posts/:postID/comments/:commentID', routes.Comments.removeComment);
let server = https.createServer(options, app);
server.listen(3000, () => {
console.log("server starting on port : " + 3000)
});
The rest of the files can be found in its git repo. (or navigate to https://www.samkeene.co.uk/blog-api/)
Would really appreciate some help.
Edit: I decided to just try if I can get even simpler app to run:
server.js
const express = require('express');
let app = express();
app.get('/', (req, res) => {
console.log("hello");
res.send('hello world')
});
app.listen(3001);
This runs into the same trouble! Connection timeout. I'm really at a lose here.