Giter VIP home page Giter VIP logo

node-js-getting-started's Introduction

node-js-getting-started

A barebones Node.js app using Express 4.

This application supports the Getting Started on Heroku with Node.js article - check it out.

Running Locally

Make sure you have Node.js and the Heroku CLI installed.

$ git clone https://github.com/heroku/node-js-getting-started.git # or clone your own fork
$ cd node-js-getting-started
$ npm install
$ npm start

Your app should now be running on localhost:5001.

Deploying to Heroku

Using resources for this example app counts towards your usage. Delete your app and database as soon as you are done experimenting to control costs.

By default, apps use Eco dynos if you are subscribed to Eco. Otherwise, it defaults to Basic dynos. The Eco dynos plan is shared across all Eco dynos in your account and is recommended if you plan on deploying many small apps to Heroku. Learn more about our low-cost plans here.

Eligible students can apply for platform credits through our new Heroku for GitHub Students program.

$ heroku create
$ git push heroku main
$ heroku open

or

Deploy to Heroku

Documentation

For more information about using Node.js on Heroku, see these Dev Center articles:

node-js-getting-started's People

Contributors

cggaurav avatar colincasey avatar danielleadams avatar dependabot[bot] avatar edmorley avatar friism avatar hunterloftis avatar jmorrell avatar jonmountjoy avatar jonnymacs avatar joshwlewis avatar lillianzhang331 avatar lyzidiamond avatar r0mdau avatar raul avatar samccone avatar scantini avatar theneva avatar toolshd avatar zackisaacs avatar zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-js-getting-started's Issues

Deploy to Heroku button in README.md on GitHub does not work

Hi!

I was checking how Deploy to Heroku button works on Heroku Dev Center. This repo node-js-getting-started is used as example for Deploy to Heroku button in the page, and it works there. "Create New App" page is displayed when I click the button.

However, when I click the Deploy to Heroku button in README.md in this repo on GitHub, "Create New App" page is not displayed, and an error page is displayed on Heroku. The error says "No app.json located in the repo URL provided. Make sure that an app.json file exists in the project root directory." I attached a screen shot here.

Do you know why the button doesn't work in README.md page? It seems the button is implemented as implicit template, and it should work in markdown file as well as html.

Thanks!

screen shot 2016-12-31 at 9 49 53 pm

Mac OS Monterey uses Port 5000

I recently attempted this getting started guide and hit an unusual error when attempting to run the app locally.

After doing some digging, I discovered that in Mac OS Monterey port 5000 is already used internally for AirPlay. Unless you go into your system settings and turn this setting off, attempting to run your app locally on this port will fail.

I'm unsure if there were any further reasons for why this port was chosen for the tutorial, but could I suggest adjusting the code to use a different port so others don't have the same issue.

Missing `require('ejs')` in `index.js`

When I do heroku local to run this locally, I get the error message

Error: Cannot find module 'ejs'

I fixed it by adding this line to the index.js file in the main directory:

var ejs = require('ejs');

Not sure if this is because I am using a dinosaur version of Node though (v0.12.7) since other people don't seem to be facing the issue as well.

(Also, thank you for the great documentation!!!) :)

TLS errors when installing pg 8

When installing the pg package latest version, the following happens when accessing the /db endpoint:

2020-04-01T21:04:18.128008+00:00 app[web.1]: Error: self signed certificate
2020-04-01T21:04:18.128018+00:00 app[web.1]: at TLSSocket.onConnectSecure (_tls_wrap.js:1473:34)
2020-04-01T21:04:18.128020+00:00 app[web.1]: at TLSSocket.emit (events.js:311:20)
2020-04-01T21:04:18.128020+00:00 app[web.1]: at TLSSocket._finishInit (_tls_wrap.js:916:8)
2020-04-01T21:04:18.128021+00:00 app[web.1]: at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:686:12) {
2020-04-01T21:04:18.128021+00:00 app[web.1]: code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
2020-04-01T21:04:18.128022+00:00 app[web.1]: }

Using pg < 8 is a temporary workaround.

Can't get this to do a simple hello world

If I make a simple hello world call on the backend in routes/index.js and try and call it from the front it doesn't work.

router.post('/hello', function(req, res, next) {
  console.log('successontheback')
  res.send('hello there sailor');
});

My call from the front end

 axios.post('http://localhost:5000/hello')
         .then((response)=>{
          console.log('response from the hello call ', response);
         })
        .catch(()=>{
          console.log('hello axios error');
        });

And the error

Failed to load resource: the server responded with a status of 404 (Not Found)
app.js:80999 hello axios error

So. Whatever configurations you have here are simply not working out of the box and I do not know how to fix them.

If I try and push my own working node.js file to heroku that works on my localhost then I get "application error" (if I push this it works, but of course there's no way that I can route to it for backend calls). Really have no idea how to get your service to work. Incredibly disappointed.

express 4

currently this boilerplate is using express 3.4 What needs to happen to get it > 4.0 ?

Redirection to another url is not working after the deployment

Use:
npm install open

const express = require('express')
const app = express()
var open=require('open')

app.get('/', (req, res) => {
res.send('Hello World!')
})

const check = () => {
for(time in notification){
if(Date.now() > notification[time].time) {
open(notification[time].url); //this open is not working after deployment
}
}
}

const PORT = process.env.PORT || 3000
app.listen(PORT, () => {
console.log(Example app listening at http://localhost:${PORT})
})

H

H

strict mode

What about putting the code under 'use strict';?

ng build help

ng build
webpack
docker

:ERROR [karma-server]: UncaughtException:: filesModified.map is not a function
04 11 2020 22:16:10.106:ERROR [karma-server]: TypeError: filesModified.map is not a function
at newCallback

docker version
Client: Docker Engine - Community
Cloud integration: 1.0.1
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:00:27 2020
OS/Arch: windows/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.24)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:14:20 2020
OS/Arch: windows/amd64
Experimental: false

ng serve

chunk {main} main.js, main.js.map (main) 1.86 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 649 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 168 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 339 kB [initial] [rendered]
Date: 2020-11-05T01:15:56.678Z - Hash: 579c0f85b3cc0387d4ad - Time: 42776ms

ERROR in Cannot read property 'tapAsync' of undefined
** Angular Live Development Server is listening on localhost:undefined, open your browser on http://localhost/ **

callback(err, filesModified.map(value => reverseReplacements.get(value) || value), contextModified.map(value => reverseReplacements.get(value) || value), missingModified.map(value => reverseReplacements.get(value) || value), reverseTimestamps(fileTimestamps), reverseTimestamps(contextTimestamps));
^

TypeError: filesModified.map is not a function
at newCallback

FROM node:latest as angular

WORKDIR /usr/src/app
COPY package*.json /code/package.json

RUN npm install --silent
COPY . .
RUN NPM run build

Specify port app runs on

EXPOSE 3000

docs

FROM nginx
RUN rm /etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY content /usr/share/nginx/html
COPY conf /etc/nginx

#Grab the latest alpine image
FROM alpine:latest

Install python and pip

RUN apk add --no-cache --update python3 py3-pip bash
ADD ./webapp/requirements.txt /tmp/requirements.txt

Install dependencies

RUN pip3 install --no-cache-dir -q -r /tmp/requirements.txt

Add our code

ADD ./webapp /opt/webapp/
WORKDIR /opt/webapp

Expose is NOT supported by Heroku

EXPOSE 5000

Run the image as a non-root user

RUN adduser -D myuser
USER myuser

Run the app. CMD is required to run on Heroku

$PORT is set by Heroku

CMD gunicorn --bind 0.0.0.0:$PORT wsgi

version: '3'
services:
web:
build: .
command: 'nodemon -L --inspect=0.0.0.0:5858'
volumes:
- '.:/code'
ports:
- '8000:8000'
- '5858:5858'
- '4200:4200'
- '3000:3000'

heroku local web error

Hi.
I was following the Getting Started on Heroku with Node.js tutorial and then when I ran "heroku local web" it gave me this error:

image

I then removed the debug flag in the Procfile and it worked.

image

The documentation also shows the Procfile without the debug file.

image

Not sure if its a bug or not or maybe node version mismatch but thought I'd let you guys know.

First time using Heroku. Really liking it!

Update: I see it was added 20 days ago in commit 1822367#diff-5bd6b85c2d6fc987875f4bf82de2a15a

Add a permissive license to the project

I've used this project to learn nodejs development with Heroku, and would like to release the code I've written under the MIT and GPL licenses, but since there's not a license declared here, that's not possible.

Would you be willing to release this under the MIT license (or GPL, or other permissive license) so anyone who forks it for learning can also release the work their work easily?

response.redirect is not a function || response.sendfile is not a function

I created nodejs app on heroku. On local, everything works fine, but in heroku logs I got this:

2018-01-05T12:03:54.148483+00:00 app[api]: Release v44 created by user [email protected] 2018-01-05T12:03:58.381790+00:00 app[web.1]: /appHello 2018-01-05T12:03:58.383453+00:00 app[web.1]: Server running at 26153 2018-01-05T12:03:58.930844+00:00 heroku[web.1]: State changed from starting to up 2018-01-05T12:04:18.574589+00:00 heroku[router]: at=info method=GET path="/" host=hidden-citadel-39641.herokuapp.com request_id=fc47fbb7-bdac-48e5- 81d6-1fd87c946f22 fwd="106.223.191.132" dyno=web.1 connect=1ms service=11ms status=200 bytes=151 protocol=https 2018-01-05T12:04:18.577684+00:00 app[web.1]: /app/server.js:14 2018-01-05T12:04:18.577705+00:00 app[web.1]: response.redirect('http://google.com'); 2018-01-05T12:04:18.577706+00:00 app[web.1]: ^ 2018-01-05T12:04:18.577707+00:00 app[web.1]: 2018-01-05T12:04:18.577708+00:00 app[web.1]: TypeError: response.redirect is not a function 2018-01-05T12:04:18.577709+00:00 app[web.1]: at Server.<anonymous> (/app/server.js:14:10) 2018-01-05T12:04:18.577710+00:00 app[web.1]: at emitTwo (events.js:106:13) 2018-01-05T12:04:18.577712+00:00 app[web.1]: at Server.emit (events.js:191:7) 2018-01-05T12:04:18.577714+00:00 app[web.1]: at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:548:12) 2018-01-05T12:04:18.577715+00:00 app[web.1]: at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23) 2018-01-05T12:04:18.686158+00:00 heroku[web.1]: State changed from up to crashed 2018-01-05T12:04:18.670728+00:00 heroku[web.1]: Process exited with status 1

Morever, I am getting error for 'response.sendfile is not a function' with small f and 'response.sendFile is not a function' with big F.

Package.json has:
"dependencies": { "body-parser": "~1.5.2", "express": "^4.8.0", "gulp-bower-fix-css-path": "^0.1.1", "gzippo": "^0.2.0", "method-override": "~2.1.2",

Server.js has:

`//Load HTTP module
var express = require('express');
const app = express();
var http = require("http");
var port = process.env.PORT|| 8000 ;
//Create HTTP server and listen on port 8000 for requests
http.createServer(function (request, response) {

// Set the response HTTP header with HTTP status and Content type
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body "Hello World"
response.end('Hello World\n');
response.redirect('http://google.com');
response.sendFile('./views/main.html');

}).listen(port);
// Catch all other routes and return the index file
app.use(express.static(__dirname + '/views'));

console.log(__dirname+"Hello");

app.get('*',function(req, res){
res.sendfile(path.join(__dirname+'/index.html'));
});
// Print URL for accessing server
console.log('Server running at '+port);`

Connect an Authenticator App

While Signup on Windows

Connect an authenticator app that generates verification codes. You can use the codes when we need to verify your identity.

Download and install an authenticator app on your mobile device.
Use the app to scan this QR code.
Enter the code generated by the app.

Verification Code: ****** That code is invalid or expired. Try another.

Using google Authenticator App

Help with making tape work with es6

EDIT : Solved ๐Ÿ‘
Turns out that building the tests WITH the sources (so instead of having a separate tests folder, place the tests folder in the same directoy as the sources) and building all at the same time solved the issue.

Hello,

I'm trying to work with es6. I already managed to use babel to build sources for the node server, but I encountered errors when trying to change unit testing done with tape to es6.

Given a simple file "settings.js" :

const settings = { version: '1.0' };
export default settings;

and the following unit test file:

import { spawn } from 'child_process';
import request from 'request';
import test from 'tape';
import SETTINGS from '../src/constants/settings';

// Start the app
const env = { ...process.env, PORT: 5000 };
const child = spawn('node', ['build/index.js'], { env });

test('responds to requests', (t) => {
  // t.plan(3);

  // Wait until the server is ready
  child.stdout.on('data', (_) => {
    // Make a request to our app
    request('http://127.0.0.1:5000/', (error, response, body) => {
      // stop the server
      child.kill();

      // No error
      t.false(error);
      // Successful response
      t.equal(response.statusCode, 200);
      const data = JSON.parse(body);
      t.equal(data.version, SETTINGS.version);
    });
  });
});

When running babel --presets es2015 -d build/ tests && node build/test.js

I get this error

npm run test

> [email protected] test /home/ganzf/Tek4/kanbord-server
> babel --presets es2015 -d build/ tests && node build/test.js

tests/test.js -> build/test.js
/home/ganzf/Tek4/kanbord-server/src/constants/settings.js:10
export default settings;
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:80:7)
    at createScript (vm.js:264:10)
    at Object.runInThisContext (vm.js:316:10)
    at Module._compile (internal/modules/cjs/loader.js:670:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Module.require (internal/modules/cjs/loader.js:643:17)
    at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `babel --presets es2015 -d build/ tests && node build/test.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ganzf/.npm/_logs/2019-02-24T07_44_24_312Z-debug.log

The server files build successfully. That should mean that there is no error in the settings.js file.
Here is the .babelrc file

{
	"presets": ["es2015", "stage-2", "env"]
}

I figured I would open an issue here as this is a boilerplate code and many people might be interested in how to turn this repository into a working ES6 server.

Thank you for your time :)

Why a Procfile

Hi, thanks for this example!

What I don't understand: Heroku should be able to guess this is a node.js project, by the package.json and also the "image": "heroku/nodejs" in app.json. So why does it still need a Procfile? Can't it just default to web: npm start if there is none?

Especially for projects that target many platforms, the less special-snowflake files you need, the cleaner your repo can be. If we'd further manage to guess lots of the info in app.json from package.json (e.g. select an appropriate heroku image based on the engines section), heroku could run many node.js projects directly, without needing any extra effort for the maintainers or the heroku user.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.