Import JSON Array from local file to typescript array
- Enable those two options in
tsconfig.json
"resolveJsonModule": true,
"esModuleInterop": true,- import the JSON File
import data from 'path/to/data.json'- make interface that suits the data
export interface Book{
id:number;
titile:string;
}- use the data as you want, for example:
@Component({...})
class Foo {
books: Book[] = data;
}To rendre images from a node.js app running on localhost:3000
- make sure that the images are in
publicoruploadsdirectories in the root directory - make sure that
app.jsincludes those lines
app.use(cors());
app.use(express.static(path.join(__dirname, "..", "public")));
app.use(express.static(path.join(__dirname, "..", "uploads")));- make sure that the image path in the src of your image tag is
http://localhost:3000/1678295679109-Linux_logo.jpg💡 note that it's
httpnothttps
- image name should be
image-name.jpgnotuploads/image-name.jpg