Skip to content

Instantly share code, notes, and snippets.

View bbachi's full-sized avatar
💭
I may be slow to respond.

Bhargav Bachina bbachi

💭
I may be slow to respond.
View GitHub Profile
@bbachi
bbachi / index.js
Last active February 13, 2019 16:37
How to write production ready Node.js Rest API with Javascript
var express = require("express"),
bodyParser = require("body-parser"),
logger = require('./logger/logger'),
app = express(),
port = 3070;
@bbachi
bbachi / Dockerfile
Last active February 13, 2019 22:53
Containarize your Node.js Rest API - Javascript verison
# from base image node
FROM node:8.11-slim
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# copying all the files from your file system to container file system
COPY package.json .
# install all dependencies
@bbachi
bbachi / index.js
Created February 14, 2019 02:48
How to write production ready Node.js Rest API with Javascript- context path
var express = require("express"),
bodyParser = require("body-parser"),
logger = require('./logger/logger'),
app = express(),
port = 3070;
app.use(bodyParser.json());
app.get("/", function(req, res) {
logger.info("default route");
@bbachi
bbachi / .eslintignore
Created February 14, 2019 06:01
How to write production ready Node.js Rest API with Javascript - eslint
node_modules/
@bbachi
bbachi / webpack.config.js
Created February 14, 2019 06:53
How to write production ready Node.js Rest API - Javascript version - webpack
const path = require('path');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'api.bundle.js'
},
target: 'node'
};
@bbachi
bbachi / Dockerfile
Created February 14, 2019 07:15
Containerize your Node.js Rest API and run it on Docker v2
# from base image node
FROM node:8.11-slim
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# copy oter files as well
COPY dist/api.bundle.js .
#expose the port
@bbachi
bbachi / package.json
Last active February 15, 2019 00:30
How to write production ready Node.js Rest API - Typescript version
{
"name": "user_api",
"version": "1.0.0",
"description": "sample rest api",
"main": "index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
@bbachi
bbachi / package.json
Last active February 15, 2019 02:23
How to write production ready Node.js Rest API - Typescript version
{
"name": "user_api",
"version": "1.0.0",
"description": "sample rest api",
"main": "index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
@bbachi
bbachi / app.ts
Last active February 15, 2019 02:46
How to write production ready Node.js Rest API - Typescript version
import * as express from 'express';
import * as bodyParser from 'body-parser';
class App {
public express: express.Application;
constructor() {
this.express = express();
this.middleware();
@bbachi
bbachi / app.ts
Created February 15, 2019 03:14
How to write production ready Node.js Rest API - Typescript version
import * as express from 'express';
import * as bodyParser from 'body-parser';
class App {
public express: express.Application;
// array to hold users
users: any[];